Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What are the java class loaders and how to use them

Shulou Source: shulou.com Published: 2022-05-31 10:52:35 09月25日 Update

This article mainly introduces what the java class loader has and how to use the relevant knowledge, the content is detailed and easy to understand, the operation is simple and fast, has a certain reference value, I believe that you read this java class loader what and how to use the article will have a harvest, let's take a look.

classification

1. Bootstrap class loader, written in C++, is a class loader that comes with JVM

Responsible for Java platform core library, used to load core class libraries. Construct ExtClassLoader and AppClassLoader, which the loader cannot get directly

Java platform core library: jre\ lib\ rt.jar, open with compression software, the classes inside are what we usually need to learn. This jre is a public jre, not a private jre under the jdk directory

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

Or-D java.ext.dirs packages the jar under the specified directory into the working library

Here jre is also a public jre

3. System class loader

Responsible for wrapping classes and jar in the directory referred to by java-classpath or-D java.class.path. It is the most commonly used loader.

Example

Package com.volcano.reflection; public class TestReflection4 {public static void main (String [] args) {/ / get the system classloader ClassLoader classLoader = ClassLoader.getSystemClassLoader (); System.out.println (classLoader); / / get the extended classloader classLoader = classLoader.getParent (); System.out.println (classLoader) / / get bootstrap classloader (which cannot be obtained directly) classLoader = classLoader.getParent (); System.out.println (classLoader); / / Test which classloader the current class is loaded by-- bootstrap classloader System.out.println (TestReflection4.class.getClassLoader ()) / / Test which class loader the built-in JDK class is loaded by-- the system class loader null System.out.println (Object.class.getClassLoader ()); / / how to obtain the path System.out.println (System.getProperty ("java.class.path")) of the loaded class of the system class loader / * the previously used commons-io and the classes written by yourself are also included * 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:\ cloud\ Code\ JavaSE\ out\ production\ basic grammar; * F:\ cloud\ Code\ JavaSE\ basic grammar\ src\ com\ lib\ commons-io-2.6.jar; * D:\ IntelliJ IDEA 2018.2.4\ lib\ idea_rt.jar * * /}} this is the end of the article on "what java class loaders have and how to use". Thank you for reading! I believe you all have a certain understanding of the knowledge of "what are the java loaders and how to use them?" if you want to learn more, you are welcome to follow the industry information channel.

Tags: Catalogue system core knowledge content foundation platform is composed of articles grammar work tests values examples that is commonly used referred to easy to operate articles easy to understand Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Shulou Tech Info Shulou Information vpn Xiaomi