Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the java class loaders and how to use them

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report