Java class loading mechanism and java Loading Mechanism
In java, class files are loaded through JVM. class loading methods include implicit loading and explicit loading. When an object is created through the new method during implicit loading, the corresponding class files are implicitly loaded to the JVM through the class loader. The class. forName () method is used to explicitly load the required class files to the JVM.
In java, classes are dynamically loaded. Instead of loading all class files to the JVM at a time, the basic class is first loaded to the JVM, other user classes are loaded into JVM when needed.
In java, classes can be divided into three categories: system class, extension class, and custom class. Different class loaders are provided for these three types of files.
Bootstrap Loader-responsible for Loading System Classes
ExtClass Loader -- responsible for loading extension classes
AppClassLoader-responsible for loading application classes
The class loading process consists of the following steps: (For details, refer to "deep understanding of Java Virtual Machine")
1. Load: Find the corresponding class file based on the search path and import it.
2. Link: links can be divided into three steps.
(1) Check: Check the correctness of the class file to be loaded
(2) preparation: allocate the static variables in the class to the memory space.
(3) parsing: Resolve a symbolic reference to a direct reference
3. Initialization: Initialize static variables and static code blocks.