Who is loading java.lang.ClassLoader?

I read how classes load. It seems the java.lang.ClassLoader instance does the job.

But who is loading java.lang.ClassLoader?

+6
source share
1 answer

Perhaps I could add this as an answer so that people can see it more easily ...

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

To quote the corresponding entry on Wikipedia: Java class loaders:

When starting the JVM, three class loaders are used:

  • Class bootloader
  • extension class loader
  • system class loader

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

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

The system class boot loader loads the 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 loader mentioned above runs in its own code (as part of the JVM executable) to load all the native Java libraries. Then the above chain of the class loader starts to load all the remaining classes that were specified on the command line and / or in the classpath arguments.

+6
source

Source: https://habr.com/ru/post/980096/


All Articles