Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Who loads java.lang.ClassLoader?

I was reading how the classes are loaded. It seems instance of java.lang.ClassLoader is doing that job.

But who loads the java.lang.ClassLoader?

like image 451
srengasamy Avatar asked Dec 23 '14 22:12

srengasamy


People also ask

Who loads the ClassLoader?

3.3. In addition, children class loaders are visible to classes loaded by their parent class loaders. For instance, classes loaded by the system class loader have visibility into classes loaded by the extension and bootstrap class loaders, but not vice-versa.

What is Java Lang ClassLoader?

A class loader is an object that is responsible for loading classes. The class ClassLoader is an abstract class. Given the binary name of a class, a class loader should attempt to locate or generate data that constitutes a definition for the class.

Which ClassLoader loads the files from JDK directory?

Extension ClassLoader: The Extension ClassLoader is a child of Bootstrap ClassLoader and loads the extensions of core java classes from the respective JDK Extension library. It loads files from jre/lib/ext directory or any other directory pointed by the system property java.

Who loads the class in Java?

ClassLoader is responsible for loading class files from file systems, networks, or any other source. There is three default class loader used in Java, Bootstrap, Extension, and System or Application class loader. Every class loader has a predefined location, from where they load class files.


1 Answers

Figured I could add this as an answer so people can see it more readily...

The java.lang.ClassLoader is part of the Java core libraries (as an abstract class) and Java-provided implementations of it are loaded by the JVM by the bootstrap class loader. The bootstrap class loader is written in native code, and is run when the JVM starts, to load all the Java libraries in $JAVA_HOME/jre/lib

To quote the relevant Wikipedia entry re: the Java Class Loaders:

When the JVM is started, three class loaders are used:

  1. Bootstrap class loader
  2. Extensions class loader
  3. System class loader

The bootstrap class loader loads the core Java libraries located in the $JAVA_HOME/jre/lib directory. This class loader, which is part of the core JVM, is written in native code.

The extensions class loader loads the code in the extensions directories ($JAVA_HOME/jre/lib/ext, or any other directory specified by the java.ext.dirs system property). It is implemented by the sun.misc.Launcher$ExtClassLoader class.

The system class loader loads code found on java.class.path, which maps to the CLASSPATH environment variable. This is implemented by the sun.misc.Launcher$AppClassLoader class.

When you start the JVM with java -cp <some classes> my.package.MainClass the bootstrap classloader mentioned above is run in native code (as part of the JVM executable) to load all Java native libraries. The class loader chain mentioned above is then kicked off to load any remaining classes that have been specified at the command line and/or in classpath arguments.

like image 177
Ryan J Avatar answered Oct 06 '22 01:10

Ryan J