A Java program is not a local executable program, and its execution relies on JVM,JVM to load the class file into the JVM before it can run inside the JVM. The component responsible for loading these classes is ClassLoader.
The JVM itself contains a classloader called **bootstrapclassloader**, and, like the JVM itself, **bootstrapclassloader** is implemented with native code (c + +, etc.), which is responsible for loading the core Java Class (such as the class in Rt.jar). In addition, the JVM provides two ClassLoader, all written in the Java language, loaded by Bootstrapclassloader into the JVM, which are **extclassloader** and **appclassloader**, where * *extclassloader** is responsible for loading the Java extension class (such as the class under Jre/lib/ext), **appclassloader** is responsible for loading the classes of the application itself (such as class under-classpath).
We can specify custom Bootstrapclassloader through the JVM parameter-xbootclasspath, but it is usually not required.
When running a program, the JVM starts, runs Bootstrap ClassLoader, and the ClassLoader loads the Java Core API (Extclassloader and Appclassloader are also loaded at this time), Then call Extclassloader to load the extension API, and finally call Appclassloader to load the class defined under the application Classpath, which is the most basic loading process for a program.
The ClassLoader that comes with the JVM just knows to load the standard Java class file from the local filesystem, but we may have the following scenario:
1) automatic verification of digital signatures prior to class load execution
2) dynamically create custom build classes that meet user-specific needs
3) Obtain class from a specific location, such as a database, network, etc.
4) custom Plus decryption class, etc.
At this time we need to customize our own Classloader,java provides a very convenient API for us to customize our own ClassLoader.
In fact, when using applets, a specific classloader is used, because Java class needs to be loaded from the network and the relevant security information is checked. In addition, most application servers use custom ClassLoader technology, and understanding the class loading principle also helps us to better develop our own applications.
# #ClassLoader结构
There are many class loaders built into Java, and this article discusses only a few core ClassLoader:
**classloader**: The base class for all class loaders, which are abstract and define the most core operations of class loading.
**secureclassloader**: Inherit from the ClassLoader, add the association class source code, the related system policy permission and so on support.
**urlclassloader**: Inherited from Secureclassloader, supports fetching class from Jar files and folders
**extclassloader**: Extension class loader, inherited from URLClassLoader, responsible for loading Java extension Class (javax.*, etc.), view the source to see that the scope is System.getproperty (" Java.ext.dirs "), usually jre/lib/ext
**appclassloader**: Application class loader, inherited from URLClassLoader, also known as the System ClassLoader (Classloader.getsystemclassloader () can get it), It loads the class under the application's classpath, looks for the range System.getproperty ("Java.class.path"), and the classes specified by-CP or-classpath are loaded by it
Java does not provide launcher source code, can refer to OpenJDK Launcher class source code.
Described above is the static class structure of classloader, conceptually, they also have a tree structure, each classloader in Java has its own parent loader (* * Attention to distinguish, not super** on the class relationship), can be obtained by classloader.getparent (), when the JVM starts to complete, by default, their tree structure is this:
Custom ClassLoader Its parent loader is Appclassloader,
The Appclassloader's parent loader is Extclassloader,
The Extclassloader's parent loader is NULL,
NULL indicates that its parent loader is bootstrapclassloader (non-Java implementation is displayed as NULL).
Reference: http://blog.csdn.net/conquer0715/article/details/38229203
JAVA ClassLoader Introduction