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.
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.
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.
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.
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With