简体   繁体   中英

Which classes are loaded by JVM but not a classloader?

I am going through th chapter on Assertions in Core Java Volume 10 by Horstmann and it says:

Some classes are not loaded by a class loader but directly by the virtual machine. You can use these switches to selectively enable or disable assertions in those classes.

I am confused by this, which classes will get loaded by the JVM and not by a class loader, I thought the bootstrap classloader loaded the initial classes?

Thanks.

According to Oracle doc, system classes without class loaders, refers all classes which is located in rt.jar and are loaded by bootstrap class loader. So, you do not access to ClassLoader object of mentioned system classes.

The bootstrap class loader loads the system classes (typically, from the JAR file rt.jar ). It is an integral part of the virtual machine and is usually implemented in C. There is no ClassLoader object corresponding to the bootstrap class loader. For example,

String.class.getClassLoader()

returns null.

Finally, we should use the -enablesystemassertions/-esa switch to enable assertions in system classes.

All Java virtual machines include one class loader that is embedded in the virtual machine. This embedded loader is called the primordial class loader. It is somewhat special because the virtual machine assumes that it has access to a repository of trusted classes which can be run by the VM without verification.

So if we write code like below:

Class r = loadClass(String className, boolean resolveIt); 

it means that class is getting loaded at runtime by classLoader and JVM is responsible to executing the program.

I hope you got it!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM