JDK内置ClassLoader的分类
- Bootstrap Class Loader
-implemented by native language
-load the core classes of jdk - Extension Class Loader
-load the class from jre/lib/ext - Application Class Loader
-load the user-define classes - Other Class Loader
-SecuerClassLoader
-URLClassLoader
通过以下代码段观察
public class TestJDKClassLoader {
public static void main(String[] args) {
System.out.println(String.class.getClassLoader());
System.out.println(com.sun.crypto.provider.AESKeyGenerator.class.getClassLoader().getClass().getName());
System.out.println(TestJDKClassLoader.class.getClassLoader().getClass().getName());
//上下两句等效
System.out.println(ClassLoader.getSystemClassLoader().getClass().getName());
}
}
输出如下
null
sun.misc.Launcher$ExtClassLoader
sun.misc.Launcher$AppClassLoader
sun.misc.Launcher$AppClassLoader
bootstrap class loader 负责将基本类核心类先加载。再由extesion class loader加载扩展类,最后自己定义的class由application class loader加载。