How is the Java Bootstrap Classloader loaded? [duplicate]
Asked Answered
D

4

36

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.

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

Drud answered 13/8, 2013 at 16:17 Comment(3)
See two detailed answers (especially by amicngh) #11395574. Also here: www2.sys-con.com/itsg/virtualcd/java/archives/0808/chaudhri/…Hammons
See - javabench.in/2012/02/java-class-loading.htmlJuvenescence
It is true that many classes from rt,jar is loaded by bootstrap classloader, but not all. To confirm just run a simple program with -verbose:class argument like "java -verbose:class HelloWorld". It will give all loaded classes by the JVM. You can notice that each and every class from rt.jar is not loaded by the JVM.Rapine
D
41

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

Dare answered 10/4, 2015 at 13:39 Comment(2)
It's hard to tell whether you are saying all classloaders are NOT Java classes. Maybe you are saying all classloaders ARE Java classes. The use of commas makes it ambiguous. (This is in the 1st sentence of your 2nd paragraph.)Fichte
I mean, in Java environment - only Bootstrap CL will be a non java (native) class loader; rest of them (System, Application, user defined CLs etc) are Java Class Loaders............. pls see the link.Juvenescence
M
10

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.

Micahmicawber answered 13/8, 2013 at 16:21 Comment(0)
F
5

There is an idiom in English, "He pulled himself up by his bootstraps." The boot straps are the little handles of the top sides of boots and, of course, its impossible.

http://en.wikipedia.org/wiki/Booting

The article explains the process of booting a computer, which is short for bootstrapping.

What happens with every program of every type is that a loader of some sort copies some bytes into memory somewhere and begins execution at a predefined place in those bytes.

For Java, the boot strap loader may or may not be a Java class. (Someone probably knows.) But it is a program of some sort that loads the very first few classes into memory and causes the JVM to begin executing those bits of loaded Java code. Maybe it loads the JVM code itself. Maybe it just makes sure some prior bit of code loaded the JVM. Maybe, it even requires the JVM to have already been loaded and running.

Its just part of the process.

Fichte answered 13/8, 2013 at 16:25 Comment(4)
Two cents: 1) Thanks for reminder, I just upvoted. 2) First half of this answer is good. Second half is full of un-certainty. I did added mu bits to it, but someone didn't considered them appropriate.Juvenescence
If you are looking for complete answer, read my answer below. (I am not blowing my trumpet, but it have the answers of all may-bes)Juvenescence
@Dare My point was that it doesn't matter what kind of code is loading the code in each step of bringing up Java. It goes without saying that, on each OS, it has to be native code that starts running. An OS only loads native code. It brings in something small which loads something larger. The process repeats with each thing loaded, in turn, loading something larger until its all there. The smaller the first part, the less native code is needed for each OS and the more common code for all OSes. But it doesn't matter how many stages there are to loading.Fichte
Yes, fully agree :-)Juvenescence
M
1

JDK installed path: jdk\jre\lib\rt.jar

this location is called bootstrap class path. Bootstrap class loader is responsible to load classes from bootstrap class path.

Bootstrap class loader is by default available with the JVM. It is implemented in Native Language Like C and C++.

Meletius answered 21/2, 2016 at 7:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.