Java class loading notes (1), java class loading notes
When a program calls a class that has not been loaded into the memory, our system will initialize the class through the following three steps:
1. class loading
Class loading refers to reading the Class file of the class into the memory and creating a java. lang. Class Object for it. The Class Loader loads binary data from the following sources:
-- 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 connection
After the Class is loaded, the system generates a Class object and then merges the binary data into the JRE. The class connection is divided into the following steps:
-- Check whether the loaded class has a correct internal structure and is consistent with other classes.
-- Allocate memory for the static Field of the class and set the default value.
-- Replace the symbolic reference in the binary data of the class with a direct reference.
3. class initialization
Class initialization mainly initializes static Filed. To specify static initialization, you can specify the initialization value by declaring the static Field, or you can specify the initialization value by using the static initialization block as the static Field.
Perform the following steps to initialize a class:
-- If this class has not been loaded and connected, load it first and then connect it.
-- When performing the first step, check whether the direct parent class of the class is initialized. If no Initialization is performed, initialize its direct parent class first (of course, when initializing the direct parent class, this direct parent class has a direct parent class, and check its direct parent class, and so on)
-- If there are initialization statements in the class, execute these initialization statements in sequence.
Reprinted please indicate the source: http://blog.csdn.net/hai_qing_xu_kong/article/details/42609883 sentiment control _