类加载器详解

package com.yang.jvm;

import sun.net.spi.nameservice.dns.DNSNameService;

public class Test {
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException {
        System.out.println(System.getProperty("sun.boot.class.path")); //bootStrap启动类的加载路径
        System.out.println(System.getProperty("java.ext.dirs")); //拓展类的加载路径
        System.out.println(System.getProperty("java.class.path"));  //应用类或者说是系统类的加载路径
        //因为字节码是使用类加载器加载的,所以每个字节码都会记录加载该字节码的类加载器,所以就可以通过字节码的getClassLoader()获得类加载器
        System.out.println(String.class.getClassLoader());//启动类加载器使用的是C或C++语言写的,所以打印启动类加载器都是返回null,
        System.out.println(DNSNameService.class.getClassLoader());//输出的是拓展类加载器sun.misc.Launcher$ExtClassLoader@2f333739
        System.out.println(Test.class.getClassLoader());//应用类加载器sun.misc.Launcher$AppClassLoader@14dad5dc


    }
}

  

原文地址:https://www.cnblogs.com/yangxiaohui227/p/11582810.html