The learning of Java ClassLoader
Java is a language that interprets execution. The Java source files written by developers are compiled into bytecode files. class form, then interpreted by the Java Virtual Machine (JVM), the. Class bytecode file itself is platform-independent, but the JVM is not, in order to achieve what is called a compilation, Everywhere, Sun provides the JVM implementations of each platform-that is, the JVM is not cross-platform, the compiled bytecode file is interpreted by the JVM on the different operating system platforms, and this chapter explains the mechanics of the JVM loading class.
What's 1.ClassLoader?
If a class is to be dispatched by the JVM, the class must first be loaded into the JVM memory, and there is a very important class classloader in the Java.lang, which is used to load classes of the specified name (under the specified path) into the JVM
Classification of 2.ClassLoader
Mainly divided into 4 categories, see the following Figure orange Section
JVM class Loader: This pattern loads the jar package under Java_home/lib
Extended class Loader: The jar package under Java_home/lib/ext is loaded
System class Loader: This is going to load the jar file specified with the Classpath parameter
User-defined class loader: Sun-provided classloader can be inherited, allowing the user to implement the ClassLoader themselves
The loading order of the ClassLoader is shown in the figure:
3. Class load Order
The JVM does not load all classes into the JVM all at once, and not every time you use a class to find it, the JVM class loader will load the default Java_home/lib class file into the JVM at startup, because these are common classes in the system, For other third party classes, then use to find, found on the cache, the next time you use this class can be directly used to cache the class object, ClassLoader is also a father-son relationship, not a ClassLoader have a father ClassLoader, The lookup order of ClassLoader with its parent ClassLoader when the class is loaded is shown in the following figure