Home > Java > javaTutorial > The use and classification of Java class loaders

The use and classification of Java class loaders

WBOY
Release: 2023-04-26 08:19:06
forward
1017 people have browsed it

Classification

1. Boot class loader, written in C, is the class loader that comes with the JVM

Responsible for Java Platform core library, used to load core class libraries. Construct ExtClassLoader and AppClassLoader. The loader cannot directly obtain the

Java platform core library: jre\lib\rt.jar. Open it with compression software. The classes inside are what we usually learn. This jre is a public jre, not a dedicated jre in the jdk directory

2. Extended class loader, is responsible for the jar package in the jre\lib\ext directory

or -D The jar package in the directory specified by java.ext.dirs is put into the working library

Here jre is also a public jre

3. System class loader

Responsible for the work of loading classes and jar packages in the directory pointed to by java -classpath or -D java.class.path. It is the most commonly used loader.

Instance

package com.volcano.reflection;
 
public class TestReflection4 {
    public static void main(String[] args) {
        //获取系统类加载器
        ClassLoader classLoader = ClassLoader.getSystemClassLoader();
        System.out.println(classLoader);
        //获取拓展类加载器
        classLoader = classLoader.getParent();
        System.out.println(classLoader);
        //获取引导类加载器(是直接无法获取的)
        classLoader = classLoader.getParent();
        System.out.println(classLoader);
 
        //测试当前类是由哪个类加载器加载的——引导类加载器
        System.out.println(TestReflection4.class.getClassLoader());
        //测试JDK内置的类是由哪个类加载器加载的——系统类加载器null
        System.out.println(Object.class.getClassLoader());
 
        //如何获得系统类加载器的加载的类的路径
        System.out.println(System.getProperty("java.class.path"));
        /*之前用过的commons-io和自己写的类也在其中
        * E:\JDK\jre\lib\charsets.jar;
        * E:\JDK\jre\lib\deploy.jar;
        * E:\JDK\jre\lib\ext\access-bridge-64.jar;
        * E:\JDK\jre\lib\ext\cldrdata.jar;
        * E:\JDK\jre\lib\ext\dnsns.jar;
        * E:\JDK\jre\lib\ext\jaccess.jar;
        * E:\JDK\jre\lib\ext\jfxrt.jar;
        * E:\JDK\jre\lib\ext\localedata.jar;
        * E:\JDK\jre\lib\ext\nashorn
        * .jar;E:\JDK\jre\lib\ext\sunec.jar;
        * E:\JDK\jre\lib\ext\sunjce_provider.jar;
        * E:\JDK\jre\lib\ext\sunmscapi.jar;
        * E:\JDK\jre\lib\ext\sunpkcs11
        * .jar;E:\JDK\jre\lib\ext\zipfs.jar;
        * E:\JDK\jre\lib\javaws.jar;
        * E:\JDK\jre\lib\jce.jar;
        * E:\JDK\jre\lib\jfr.jar;
        * E:\JDK\jre\lib\jfxswt.jar;
        * E:\JDK\jre\lib\jsse.jar;
        * E:\JDK\jre\lib\management-agent.jar;
        * E:\JDK\jre\lib\plugin.jar;
        * E:\JDK\jre\lib\resources.jar;
        * E:\JDK\jre\lib\rt.jar;
        * F:\云\Code\JavaSE\out\production\基础语法;
        * F:\云\Code\JavaSE\基础语法\src\com\lib\commons-io-2.6.jar;
        * D:\IntelliJ IDEA 2018.2.4\lib\idea_rt.jar
 
         * */
    }
}
Copy after login

The above is the detailed content of The use and classification of Java class loaders. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template