Java in the need to use the category when the class is loaded, Java class loading is by the class loader (class loader) to achieve, preset, after the program starts, there will be three categories loader: Bootstrap loader, Extclassloader and Appclassloader.
Bootstrap Loader is written by C + +, The default is to search for the classes or LIB directory in the directory where the JRE resides. The jar file (for example, Rt.jar) has a specified category and is loaded (actually specified by the system parameter Sun.boot.class.path); The preset extclassloader is responsible for searching the directory where the JRE resides. The classes or. jar in the Lib/ext directory has the specified category and is loaded (actually specified by the system parameter Java.ext.dirs); Appclassloader searches Whether the specified classes is in the Classpath and is loaded (specified by the system parameter Java.class.path).
The Bootstrap Loader is loaded after the JVM is booted, and then it loads the Extclassloader and sets the Extclassloader's parent to Bootstrap Loader, The Bootstraploader then loads the Appclassloader and sets the Appclassloader parent to Extclassloader.
When a category is loaded, each class loader first takes the task of loading the category to its parent, and if the parent cannot find it, it is the responsibility to load it, and if he cannot find it, it will throw out the noclassdeffounderror.
After each class is loaded, there is a class instance to represent it, and each class instance remembers which ClassLoader loaded it, and the class's getClassLoader () gets the ClassLoader to load the class.
The relationship of three class loaders in Java and the scope of the classes that are loaded separately