【Java】Basic knowledge

4-23 Class loading
Java class loading is to read the binary data of the .class file into memory, put it in the method area of ​​the runtime data area, and create a java.lang.class object on the heap area , The object encapsulates the data structure of the class in the method area, and provides the user with an interface related to the data structure in the method area.
The class loader does not wait until a class is used for the first time before loading it. The JVM allows the class loader to pre-load it when it is about to be used. If the use of pre-loading encounters a .class file missing or If there is an error, the class loader will report an error when the class is used for the first time. If it is not used, it will not report an error.
The loading process of classes includes loading verification, preparation, parsing and initialization.
The loading of classes includes
1. Initial loading by the JVM when the command line starts the application
2. Dynamic loading through the Class.forName() method.
3. Dynamic loading through ClassLoader.loaderClass()
Parent delegation Mechanism: When a class loader receives a request, it will not load the class itself first, or will it pass it to the parent object, and then pass it up until it is passed to the heuristic class loader, which is loaded by the heuristic class The class loader will actively try to load the class only if the required class is not found in the search scope.

4-23 Binding
Associating a method with a class or object is called binding. There are two types of binding, static binding and dynamic binding.
Static binding: Before the method runs, it is known to which one the method belongs class, then you can connect to the class and locate that method at compile time.
Dynamic binding: During the running process of the program, which method can be determined according to the specific instance object.
Each class is loaded into the virtual machine At the time, metadata is saved in the method area, which contains a method table, each item of this table is the code pointing to a specific method, if the method of this class is overridden, then this table item will point to the new code.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324751701&siteId=291194637