1).JVM 核心类加载器(ClassLoader)有如下几种类加载器 :

    1.引导类加载器(bootstrapLoader):负责加载支撑JVM运行的位于JRE的lib目录下的核心类库,比如 rt.jar、charsets.jar等
    2.扩展类加载器(extClassloader):负责加载支撑JVM运行的位于JRE的lib目录下的ext扩展目录中的JAR 类包
    3.应用程序类加载器(appClassLoader):负责加载ClassPath路径下的类包,主要就是加载你自己写的那些类
    4.自定义加载器:负责加载用户自定义路径下的类包

    2).以下代码程序可以查看程序启动运行都加载了那些文件包:

    1. package com.tuling.jvm;
    2. import sun.misc.Launcher;
    3. import java.net.URL;
    4. public class TestJDKClassLoader {
    5. public static void main(String[] args) {
    6. System.out.println(String.class.getClassLoader());
    7. System.out.println(com.sun.crypto.provider.DESKeyFactory.class.getClassLoader().getClass().getName());
    8. System.out.println(TestJDKClassLoader.class.getClassLoader().getClass().getName());
    9. System.out.println();
    10. ClassLoader appClassLoader = ClassLoader.getSystemClassLoader();
    11. ClassLoader extClassloader = appClassLoader.getParent();
    12. ClassLoader bootstrapLoader = extClassloader.getParent();
    13. System.out.println("the bootstrapLoader : " + bootstrapLoader);
    14. System.out.println("the extClassloader : " + extClassloader);
    15. System.out.println("the appClassLoader : " + appClassLoader);
    16. System.out.println();
    17. System.out.println("bootstrapLoader加载以下文件:");
    18. URL[] urls = Launcher.getBootstrapClassPath().getURLs();
    19. for (int i = 0; i < urls.length; i++) {
    20. System.out.println(urls[i]);
    21. }
    22. System.out.println();
    23. System.out.println("extClassloader加载以下文件:");
    24. System.out.println(System.getProperty("java.ext.dirs"));
    25. System.out.println();
    26. System.out.println("appClassLoader加载以下文件:");
    27. System.out.println(System.getProperty("java.class.path"));
    28. }
    29. }

    3).打印结果:
    image.png
    appClassLoader加载以下文件:
    C:\Program Files\Java\jdk1.8.0_212\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.8.0_212\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.8.0_212\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.8.0_212\jre\lib\ext\cldrdata.jar;C:\Program Files\Java\jdk1.8.0_212\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.8.0_212\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.8.0_212\jre\lib\ext\jfxrt.jar;C:\Program Files\Java\jdk1.8.0_212\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.8.0_212\jre\lib\ext\nashorn.jar;C:\Program Files\Java\jdk1.8.0_212\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.8.0_212\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.8.0_212\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.8.0_212\jre\lib\ext\sunpkcs11.jar;C:\Program Files\Java\jdk1.8.0_212\jre\lib\ext\zipfs.jar;C:\Program Files\Java\jdk1.8.0_212\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.8.0_212\jre\lib\jce.jar;C:\Program Files\Java\jdk1.8.0_212\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.8.0_212\jre\lib\jfxswt.jar;C:\Program Files\Java\jdk1.8.0_212\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.8.0_212\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.8.0_212\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.8.0_212\jre\lib\resources.jar;C:\Program Files\Java\jdk1.8.0_212\jre\lib\rt.jar;H:\JGS\JGSTest\target\classes;C:\Program Files\JetBrains\IntelliJ IDEA 2020.1.1\lib\idea_rt.jar;C:\Users\60907\AppData\Local\JetBrains\IntelliJIdea2020.1\captureAgent\debugger-agent.jar
    实际上appClassLoader只加载H:\JGS\JGSTest\target\classes下的文件,对于打印出来的其它的这些文件不是加载的。