1. Loading process for classes
The JVM divides the class loading process into three steps: Mount (load), link, and Initialize (Initialize) links are divided into three steps, as follows:
1) Load: Find and load the binary data of the class;
2) Links:
Validation: Ensure that the class being loaded is correct;
Prepare: Allocates memory for static variables of the class and initializes them to default values;
Parse: Converts a symbolic reference in a class to a direct reference;
3) Initialization: Assigns the correct initial value to the static variable of the class;
Then why do I have to verify this step? First of all, if the class file generated by the compiler, it must be in accordance with the JVM bytecode format, but in case a master himself wrote a class file,
Let the JVM load and run, for malicious purposes, it is not good, so the class file to verify the first pass, non-conforming will not let it continue to execute, but also for security reasons.
The preparation phase and initialization phase seem a bit Shang, in fact, is not Shang, if the class has a statement: private static int a = 10, it is the execution of the process is such, first byte-code file is
After loading into memory, verify this step first, verify through the post-preparation phase, assign memory to a, because the variable a is static, so at this point a equals the default initial value of type int 0,
That is, a=0, then to the parsing (later said), to the initialization of this step, the real value of a of 10 is assigned to a, at this time a=10.
2. Initialization of Classes
When the class is initialized:
1) Create an instance of the class, that is, the new object
2) Access a static variable of a class or interface, or assign a value to the static variable
3) Calling the static method of the class
4) Reflection (Class.forName ("Com.lyj.load"))
5) Initializes a subclass of a class (the parent class of the child class is initialized first)
6) Startup class indicated at the start of the JVM, which is the same class with the same file name and class name
Only these 6 cases will cause the class's class to be initialized.
Initialization steps for the class:
1) If this class has not been loaded and linked, then load and link it first
2) If the class has a direct parent class, and the class has not been initialized (note: In a classloader, the class can only be initialized once), then initialize the immediate parent class (not for the interface)
3) If there is an initialization statement (such as a static variable and a static block) in the join class, then the initialization statements are executed sequentially.
3. Loading of Classes
The loading of a class refers to reading the binary data in the class's. class file into memory, placing it in the method area of the run-time data area, and creating a Java.lang.Class object of this class in the heap area.
The object used to encapsulate the class in the method area class.
The final product loaded by the class is a class object in the heap that encapsulates the data structure of the class within the method area, and provides the Java programmer with an interface to access the data structures within the method area
There are several ways to load classes:
1) load directly from the local system
2) Download the. class file over the network
3) load. class files from archive files such as Zip,jar
4) Extract the. class file from the proprietary database
5) Dynamically compile Java source files into a. class file (server)
4. Loader
From http://blog.csdn.net/cutesource/article/details/5904501
The class loading of the JVM is done through ClassLoader and its subclasses, and the hierarchy and loading order of the classes can be described as follows:
1) Bootstrap ClassLoader
Responsible for loading all classes in Jre/lib/rt.jar in $java_home, implemented by C + +, not classloader subclasses
2) Extension ClassLoader
Some jar packages that are responsible for loading the extensions in the JAVA platform, including the jar packages in $java_home Jre/lib/*.jar or-djava.ext.dirs specified directories
3) App ClassLoader
Responsible for documenting the jar packages specified in the Classpath and the class in the directory
4) Custom ClassLoader
The ClassLoader that the application customizes according to its own needs, such as Tomcat and JBoss, will be implemented according to the Java EE specification itself ClassLoader
The load process checks to see if the class is loaded, the check order is bottom-up, and the custom ClassLoader to bootstrap ClassLoader-by-layer check, as long as a certain classloader is loaded as if the class has been loaded. Ensure that only all classloader of this class are loaded once. The order of loading is top-down, that is, the upper layer tries to load the class one at a level.
Java ClassLoader Summary