Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How is the Java Bootstrap Classloader loaded? [duplicate]

In java, it is said that all the classes are being loaded by classloaders.

So first of all, bootstrap classloader loads all the rt.jar classes.

So I am still confused as Classloader is also a class, so who will load this BootStrapClassloader.

Kindly explain.

like image 372
Sunny Gupta Avatar asked Aug 13 '13 16:08

Sunny Gupta


People also ask

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.

Can we load the same class by two ClassLoader?

So when a class is loaded into JVM, you have an entry as (package, classname, classloader). Therefore the same class can be loaded twice by two different ClassLoader instances.

What is bootstrap ClassLoader in Java?

BootStrap ClassLoader: A Bootstrap Classloader is a Machine code which kickstarts the operation when the JVM calls it. It is not a java class. Its job is to load the first pure Java ClassLoader. Bootstrap ClassLoader loads classes from the location rt. jar.

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.


2 Answers

Answer : When a JVM starts up, a special chunk of machine code runs that loads the system classloader. This machine code is known as the Bootstrap / Primordial (or sometimes - Null) classloader.

It is not a Java class at all, as are all other classloaders. The bootstrap classloader is platform specific machine instructions that kick off the whole classloading process.

All classloaders, with the exception of the bootstrap classloader, are implemented as Java classes. Something must load the very first Java classloader to get the process started. Loading the first pure Java classloader is the job of the bootstrap classloader.

The bootstrap classloader also takes care of loading all of the code needed to support the basic Java Runtime Environment (JRE), including classes in the java.util and the java.lang packages.

Source: http://www.theserverside.com/tutorial/Classloaders-Demystified-Understanding-How-Java-Classes-Get-Loaded-in-Web-Applications

like image 146
Raúl Avatar answered Sep 21 '22 01:09

Raúl


The Bootstrap Classloader, being a classloader and all, is actually a part of the JVM Core and it is written in native code.

Classloaders can be objects, they need a representation too. In fact, this also allows the creation of user-defined classloaders.

like image 21
Fritz Avatar answered Sep 20 '22 01:09

Fritz