to understand the class loader, first understand the loadI. Loading of classes (overview of loading classes)When a program wants to use a class, if the class has not yet been loaded into memory, the system initializes the class by loading, connecting, and initializing three steps.
1. Loading
- This means reading the class file into memory and creating a class object for it.
- When any class is used, the system creates a class object.
where the class object is the focus of the reflection to be reflected in the next section. This class object describes all of the information about this object, such as what constructs are available, what member methods are available, and what fields are available. 2. Connection
- Verify that you have the correct internal structure and that it is consistent with other classes
- Prepare to allocate memory for static members of the class and set default initialization values
- Resolve to replace a symbolic reference in a class's binary data with a direct reference
3. Initialization
is the initial steps we've talked about before.Class 3.1 Initialization time (class initialization time)
- To create an instance of a class
- Access static variables for a class, or assign a value to a static variable
- To invoke a static method of a class
- Use reflection to force the creation of a class or interface corresponding to the Java.lang.Class object (this is reflection, the reverse load Class)
- Initializes a subclass of a class
- To run a main class directly using the Java.exe command
second, class loader1. Class loader
- Responsible for loading the. class file into memory and generating the corresponding class object for it.
- Although we do not need to care about the class loading mechanism, we understand this mechanism and we can better understand the operation of the program.
2, the composition of the class loader
- Bootstrap ClassLoader Root class Loader
- Extension ClassLoader Extension Class loader
- Sysetm ClassLoader System Class Loader
3, the Role of class loader3.1 Bootstrap ClassLoader root class loaderalso known as the Boot class loader, which is responsible for loading Java core classes
such as system,string and so on. In the Rt.jar file under the Lib directory of the JRE in the JDK
3.2 Extension ClassLoader extension class loaderresponsible for loading the jar packages in the extended directory of the JRE.
The Lib directory of the JRE in the JDK under the EXT directory
3.3 System ClassLoader class loaderresponsible for loading the class file from the Java command when the JVM starts, and the jar package and classpath specified by the CLASSPATH environment variable
Java Basics-Class loader