java virtual machine (ten) --- introduction to class loader

Java virtual machine (ten)-introduction to class loader

  1. JVM supports two kinds of class loaders, Bootstrap ClassLoader and User-Defined ClassLoader.
  2. Conceptually, custom loader generally refers to a type of loader customized by developers, but the Java virtual machine specification does not define it as such. Instead, all class loaders derived from the abstract class ClassLoader are classified as custom Class loader.
    Insert picture description here
    In the above figure, Bootstrap Class Loader is the bootstrap class loader, and the others are custom class loader.
    The relationship of the four here is the containment relationship, not the upper and lower layers, nor the parent-child inheritance relationship.
    It can also be classified from the writing language. Bootstrap Class Loader is written in c and c++, and the others are written in java language.
  3. A first look at class loader
public class testsss {
    
    

    public static void main(String[] args) {
    
    
        //获取系统类加载器
        ClassLoader systemClassLoader = ClassLoader.getSystemClassLoader();
        System.out.println(systemClassLoader);//sun.misc.Launcher$AppClassLoader@18b4aac2

        //获取其上层,扩展类加载器
        ClassLoader extClassLoader = systemClassLoader.getParent();
        System.out.println(extClassLoader);//sun.misc.Launcher$ExtClassLoader@119d7047

        //试图获取引导类加载器
        ClassLoader bootstrapClassLoader = extClassLoader.getParent();
        System.out.println(bootstrapClassLoader);//null

        //对于用户自定义类的加载器  ==> 使用系统类加载器加载
        ClassLoader classLoader = testsss.class.getClassLoader();
        System.out.println(classLoader);//sun.misc.Launcher$AppClassLoader@18b4aac2

        //String类是使用引导类加载器加载, java的核心类库都是使用引导类加载器加载
        ClassLoader classLoader1 = String.class.getClassLoader();
        System.out.println(classLoader1);//null

    }
}

》》》Bloggers update their learning experience for a long time, recommend likes and follow! ! !
》》》If there is something wrong, please leave a message in the comment area, thank you! ! !

Guess you like

Origin blog.csdn.net/qq_41622739/article/details/105056009