Author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/
1. role:
It is used to load classes to JVM virtual machines.
2. loading process features:
When loader1 is requested to load the sample class, loader1 first delegates its parent loader to load the sample class. If the parent loader cannot be loaded, loader1 itself loads the class. This ensures the security of the Java platform.
3. Category:
A) Root (bootstrap) Loader: The loader does not have a parent loader and is responsible for loading the core class library of the virtual machine. Its implementation depends on the underlying operating system and is part of the implementation of virtual machines.
B) Extension Class Loader: its parent loader is the root class loader and is responsible. ext. load the class in the directory specified by the dirs system attribute, or load the class library from the JRE/LIV/EXT subdirectory of the JDK installation directory. It is a pure Java class and a subclass of Java. Lang. classloader.
C) system class loader (also known as the application Class Loader). Its Parent loader is an extended class loader and is responsible for Java from the environment variable classpath or system attribute. class. the path specifies the directory to load the class, which is the default parent loader of the User-Defined class. It is a pure Java class and a subclass of Java. Lang. classloader.
4. Specific loading process: Class sampleclass = loader2.loadclass ("sample ");
Loader2 first checks whether the sample class has been loaded from its namespace. If it has been loaded, it returns a reference to the class object representing the sample class. If not loaded, loader2 will step by step request the parent loaders at all levels to load until the top, and then return the loading success message layer by layer. If no one is successful, the classnotfound exception is thrown. If a class loader can be loaded successfully, it is called the definition Class Loader. All the class loaders that can successfully return a reference to the Class Object (including the definition Class Loader) these are called the initial class loaders.
Note: the parent-child relationship between loaders does not refer to inheritance, but to the packaging relationship between loader objects. A parent-child loader may be two instances of the same loading class, for example:
Classloader loader1 = new myclassloader ();
Classloader loader2 = new myclassloader (loader1); // The loader1 parameter is used as the parent loader of loader2.
5. namespace definition:
Each class loader has its own namespace, which is composed of the loader and all the classes loaded by the parent class loader.
6. runtime package:
A running package is composed of classes loaded by the same class loader that belong to the same package. It determines whether two classes belong to the same runtime package, not only whether the package name is the same, check whether the class loaders are the same.
7. Create a custom Class Loader
By extending the java. Lang. classloader class and then overwriting its findclass (string name) method, this method returns a reference to the corresponding class object based on the class name specified by the parameter. Specific can refer to the http://blog.csdn.net/assre/archive/2006/01/18/583398.aspx
Author: gnuhpc
Source: http://www.cnblogs.com/gnuhpc/