JDK11和JDK8类加载器的区别
itteer 人气:0如下代码:
public class Test07 {
public static void main(String[] args) throws ClassNotFoundException {
// 获取系统类加载器
ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
System.out.println(systemClassLoader);
// 获取系统类加载器的父类加载器 --> 扩展类加载器
ClassLoader parent = systemClassLoader.getParent();
System.out.println(parent);
// 获取扩展类加载器的父类加载器 --> 根加载器(C/C++)
ClassLoader parent1 = parent.getParent();
System.out.println(parent1);
// 测试当前类的加载器
ClassLoader classLoader = Class.forName("com.itteer.reflection.Test07").getClassLoader();
System.out.println(classLoader);
// 测试JDK内置的类加载器
classLoader = Class.forName("java.lang.Object").getClassLoader();
System.out.println(classLoader);
// 如何获得系统类加载器可以加载的路径
System.out.println(System.getProperty("java.class.path"));
}
}
使用JDK11编译,输出结果如下:
jdk.internal.loader.ClassLoaders$AppClassLoader@1f89ab83
jdk.internal.loader.ClassLoaders$PlatformClassLoader@7c30a502
null
jdk.internal.loader.ClassLoaders$AppClassLoader@1f89ab83
null
D:\IDEAWorkspace\demo\anno
使用JDK8编译,输出结果如下:
sun.misc.Launcher$AppClassLoader@18b4aac2
sun.misc.Launcher$ExtClassLoader@1b6d3586
null
sun.misc.Launcher$AppClassLoader@18b4aac2
null
D:\Java\jdk1.8.0\jre\lib\charsets.jar;
D:\Java\jdk1.8.0\jre\lib\deploy.jar;
D:\Java\jdk1.8.0\jre\lib\ext\access-bridge-64.jar;
D:\Java\jdk1.8.0\jre\lib\ext\cldrdata.jar;
D:\Java\jdk1.8.0\jre\lib\ext\dnsns.jar;
D:\Java\jdk1.8.0\jre\lib\ext\jaccess.jar;
D:\Java\jdk1.8.0\jre\lib\ext\jfxrt.jar;
D:\Java\jdk1.8.0\jre\lib\ext\localedata.jar;
D:\Java\jdk1.8.0\jre\lib\ext\nashorn.jar;
D:\Java\jdk1.8.0\jre\lib\ext\sunec.jar;
D:\Java\jdk1.8.0\jre\lib\ext\sunjce_provider.jar;
D:\Java\jdk1.8.0\jre\lib\ext\sunmscapi.jar;
D:\Java\jdk1.8.0\jre\lib\ext\sunpkcs11.jar;
D:\Java\jdk1.8.0\jre\lib\ext\zipfs.jar;
D:\Java\jdk1.8.0\jre\lib\javaws.jar;
D:\Java\jdk1.8.0\jre\lib\jce.jar;
D:\Java\jdk1.8.0\jre\lib\jfr.jar;
D:\Java\jdk1.8.0\jre\lib\jfxswt.jar;
D:\Java\jdk1.8.0\jre\lib\jsse.jar;
D:\Java\jdk1.8.0\jre\lib\management-agent.jar;
D:\Java\jdk1.8.0\jre\lib\plugin.jar;
D:\Java\jdk1.8.0\jre\lib\resources.jar;
D:\Java\jdk1.8.0\jre\lib\rt.jar;
D:\IDEAWorkspace\demo\anno;
C:\Program Files\JetBrains\IntelliJ IDEA 2019.3.1\lib\idea_rt.jar
加载全部内容