Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What loads the java system classloader?

We know that we can override the System classloader with:

java -Djava.system.class.loader=com.test.MyClassLoader xxx 

Then, since com.test.MyClassLoader itself is a class, by whom is it loaded?

How do we get the class file of this "meta" classloader?

like image 634
James.Xu Avatar asked Jul 09 '12 12:07

James.Xu


People also ask

What is system ClassLoader in Java?

The Java ClassLoader is a part of the Java Runtime Environment that dynamically loads Java classes into the Java Virtual Machine. The Java run time system does not need to know about files and file systems because of classloaders. Java classes aren't loaded into memory all at once, but when required by an application.

How does a ClassLoader work in Java?

A Java Class is stored in the form of byte code in a . class file after it is compiled. The ClassLoader loads the class of the Java program into memory when it is required. The ClassLoader is hierarchical and so if there is a request to load a class, it is delegated to the parent class loader.

Which ClassLoader loads the files from JDK directory?

5. Which class loader loads jar files from JDK directory? Explanation: Extension loads jar files from lib/ext directory of the JRE. This gives the basic functionality available.

Where is ClassLoader located in Java?

The system class loader loads code found on java. class. path , which maps to the CLASSPATH environment variable.


2 Answers

Bootstrap classloader is the parent of all classloaders and loads the standard JDK classes in lib directory of JRE (rt.jar and i18n.jar). All the java.* classes are loaded by this classloader.

Extensions Classloader is the immediate child of Bootstrap classloader. This classloader loads the classes in lib\ext directory of the JRE.

System-Classpath classloader is the immediate child of Extensions classloader. It loads the classes and jars specified by the CLASSPATH environment variable

You could try to inject your custom class loader by means of the "java.system.class.loader" property (see ClassLoader#getSystemClassLoader).

Default System class loader is parent for MyClassLoader instances,

like image 129
amicngh Avatar answered Oct 11 '22 11:10

amicngh


From the Javadoc for ClassLoader.getSystemClassLoader:

If the system property "java.system.class.loader" is defined when this method is first invoked then the value of that property is taken to be the name of a class that will be returned as the system class loader. The class is loaded using the default system class loader and must define a public constructor that takes a single parameter of type ClassLoader which is used as the delegation parent.

The default system class loader itself is specific to the JVM implementation.

like image 32
casablanca Avatar answered Oct 11 '22 11:10

casablanca