类加载器

类加载器

类加载器的作用


代码如下

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.lu.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"));
        
        //双亲委派机制 
        //多重检测安全性
            //java.lang.String -->
        
        /*
        C:\Program Files\Java\jdk1.8.0_231\jre\lib\charsets.jar;
        C:\Program Files\Java\jdk1.8.0_231\jre\lib\deploy.jar;
        C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\access-bridge-64.jar;
        C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\cldrdata.jar;
        C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\dnsns.jar;
        C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\jaccess.jar;
        C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\jfxrt.jar;
        C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\localedata.jar;
        C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\nashorn.jar;
        C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\sunec.jar;
        C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\sunjce_provider.jar;
        C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\sunmscapi.jar;
        C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\sunpkcs11.jar;
        C:\Program Files\Java\jdk1.8.0_231\jre\lib\ext\zipfs.jar;
        C:\Program Files\Java\jdk1.8.0_231\jre\lib\javaws.jar;
        C:\Program Files\Java\jdk1.8.0_231\jre\lib\jce.jar;
        C:\Program Files\Java\jdk1.8.0_231\jre\lib\jfr.jar;
        C:\Program Files\Java\jdk1.8.0_231\jre\lib\jfxswt.jar;
        C:\Program Files\Java\jdk1.8.0_231\jre\lib\jsse.jar;
        C:\Program Files\Java\jdk1.8.0_231\jre\lib\management-agent.jar;
        C:\Program Files\Java\jdk1.8.0_231\jre\lib\plugin.jar;
        C:\Program Files\Java\jdk1.8.0_231\jre\lib\resources.jar;
        C:\Program Files\Java\jdk1.8.0_231\jre\lib\rt.jar;
        C:\Users\99714\Desktop\JavaSE\out\production\基础语法;
        C:\Users\99714\Desktop\JavaSE\基础语法\src\com\lib\commons-io-2.7.jar;
        D:\IntelliJ IDEA 2019.2.4\lib\idea_rt.jar

         */
    }
}
posted @ 2020-07-17 01:44  小卢传  阅读(109)  评论(0编辑  收藏  举报