In java, class files are loaded through the JVM. The class loading methods are divided into implicit loading and explicit loading. Among them, when an object is created through new during implicit loading, the corresponding class file is implicitly loaded into the JVM through the class loader. Explicit loading explicitly loads the required class files into the JVM through class.forName().
In the Java language, classes are loaded dynamically. Instead of loading all class files into the JVM at once, the basic classes are loaded into the JVM first, and other user classes are loaded into the JVM when needed. Loaded into JVM.
In the Java language, classes can be divided into three categories: system classes, extension classes and custom classes. Different class loaders are provided for these three types of files
Bootstrap Loader -- Responsible Loading system classes
ExtClass Loader -- Responsible for loading extension classes
AppClassLoader -- Responsible for loading application classes
The class loading process mainly includes the following steps (For details, please refer to "In-depth Understanding of Java Virtual Machine")
1. Loading: Find the corresponding class file according to the search path, and then import it.
2. Link: The link can be divided into 3 steps
(1) Check: Check the correctness of the class file to be loaded
(2)Preparation: Put the class in Allocate memory space for static variables
(3) Parsing: Parse symbol references into direct references
3. Initialization: Perform initialization work on static variables and static code blocks.
The above is the detailed content of Detailed explanation of examples of class loading mechanism in Java. For more information, please follow other related articles on the PHP Chinese website!