When a program calls a class and the class is not loaded into memory, our system initializes the class with the following three steps:
1. Loading of classes
Class loading refers to the reading of a class file into memory and creating a Java.lang.Class object for it. Class is loaded by the class loader, we can load binary data from the following sources through the ClassLoader:
--Load the class file from the local file system.
--Load the class file from the jar package.
--Load the class file from the network.
--Dynamically compile and load a Java source file.
2, Class of connection
When the class is loaded, a class object is generated and then the binary data is merged into the JRE. Class joins are then divided into the following steps:
--Verify that the class being loaded has the correct internal structure and is consistent with other classes.
--allocates memory for the static field of the class and sets the default value.
--Replace the symbolic reference in the binary data of the class with a direct reference.
3. Initialization of class
The initialization of a class is primarily initialized with static filed, specifying that static initialization can specify initialization values by declaring a static field, and you can specify initialization values for static field by static initialization blocks.
The initialization of a class is primarily based on the following steps:
--If the class has not been loaded and connected, then the class will be connected before loading.
--When performing the first step, you should check whether the immediate parent class of the class is initialized, and if not initialized, initialize its immediate parent class (of course, when initializing the direct parent class, the immediate parent class has a direct parent class, and the immediate parent class is checked, and so on)
--If there are initialization statements in the class, then execute the initialization statements in turn.
Reprint Please specify source: http://blog.csdn.net/hai_qing_xu_kong/article/details/42609883 Emotional Control _
Java class Load notes (1)