1.JDK built
In addition other classes only root class loader . 1 parent of loader
Popular that parents appoint mechanisms:
One class loader want to load a particular class, and not immediately to be loaded by himself, but his father entrusted to the loader is completed, if the parent loader still above the parent loader, then entrusted to his father's father, has been up constantly traced until the root class loader from the root class loader particular class, if the root class loader can not load, put down the flow returns to the expansion of the loader, has been down. In this process, as long as there is a class loader loads successfully, it returns a success
Root class loader: the JRE \ lib \ rt.jar or -Xbootclasspath option specifies the jar package
Expand the class loader: . The JRE \ lib \ \ * jar EXT or -Djava.ext.dirs specified directory jar package
System class loader: the CLASSPATH or Djava.class.path class and the directory specified in the jar package
Custom class loader: the java.lang.ClassLoader subclass loading custom class
2.JDK acquired class loader
* Returns the class loader for the class. Some implementations may use * null to represent the bootstrap class loader. This method will return * null in such implementations if this class was loaded by the bootstrap * class loader. public class Test3 { public static void main(String[] args) throws ClassNotFoundException { Class<?> clazz = Class.forName("java.lang.String"); System.out.println(clazz.getClassLoader()); } } class C{ }
console:
Null
Cause: returns null, description String class loader is the root class loader
public class Test3 { public static void main(String[] args) throws ClassNotFoundException { Class<?> clazz = Class.forName("java.lang.String"); System.out.println(clazz.getClassLoader()); Class<?> clazz2 = Class.forName("com.cn.test.Test3"); System.out.println(clazz2.getClassLoader()); } } class C{ }
console:
null sun.misc.Launcher$AppClassLoader@73d16e93