Java's 3 loaders
-
Boot class loader
BootStrapClassLoader
-
Extended class loader
ExtensionClassLoader
-
Application class loader
ApplicationClassLoader
The three types of loaders can be simply understood as:
BootStrapClassLoader
What is loaded is the class library of JVM core classes is
ExtensionClassLoader
loaded is the class library of extended classes
ApplicationClassLoader
Loads the java class library written by ourselves
Which libraries are loaded by the class loader
jdk1.8 in BootStrapClassLoader
load D:\Program Files\Java\jdk1.8.0_201\jre\lib
under
- resources.jar
- rt.jar
- sunrsasign.jar
- jsse.jar
- jce.jar
- charsets.jar
- jfr.jar
andD:/Program Files/Java/jdk1.8.0_201/jre/classes
folders under the class file
ExtensionClassLoader
Load java extension class library
D:\Program Files\Java\jdk1.8.0_201\jre\lib\ext
for example
- access-bridge-64.jar
- cldrdata.jar
- dnsns.jar
- jaccess.jar
- jfxrt.jar
- localedata.jar
- nashorn.jar
- sunec.jar
- sunjce_provider.jar
- sunmscapi.jar
- sunpkcs11.jar
- zipfs.jar
ApplicationClassLoader
Load application class
The process of java application startup:
- First, the
.java
file is compiled into a.class
file by javac . - When we start
java程序
, the.class
file is loaded into memory through the class loading subsystem, which is divided into three loaders (BootStrapClassLoader、ExtensionClassLoader、ApplicationClassLoader
).
First, you need to load the java-based class library (described above), that is,BootStrapClassLoader
load the java class library, when the boot class loader is loaded, thenExtensionClassLoader
load the extended class library, and thenApplicationClassLoader
load the class where the main method is located into the memory .
In the process of running the program will be used in other types of documents, loaded in addition to the main method that category, there is a parent delegation mechanism classes and sandbox mechanism , it can be simply understood as the first inquiryBootStrapClassLoader
there will be classes loaded into memory, if not Then ask ifExtensionClassLoader
this class has been loaded into memory. If it has not been loaded before, it will be usedApplicationClassLoader
for loading.BootStrapClassLoader、ExtensionClassLoader
The class path they load is fixed, so the classes they load are also relatively fixed (unless they put their classes under the class library path). - The class loading subsystem is further divided into: loading, linking, and initialization .
The class loaded into the memory will be loaded, verified, prepared, parsed, initialized (主要是 静态成员变量、静态代码块 的初始化
), and loaded into the memory after the initialization is complete