The reason for having three basic class loaders (Bootstrap, extension, system) is mainly security.
Prior to version 1.2, the JVM had only one default class loader, which is currently called the Bootstrap class loader.
The path of classes loaded by class loaders is that each class loader first calls its parent, and if this parent does not find the requested class, the current one searches for it.
The key concept is the fact that the JVM will not provide access to the package (access to these methods and fields unless you specifically specify private , public or protected ) if the class that requests this access comes from the same classloader that loads the class he wants to access.
So, suppose the user calls his class java.lang.MyClass . Theoretically, he could access the packages for all fields and methods in the java.lang and change the way they work. Language itself does not interfere with this. But the JVM blocks this because all real java.lang classes have been loaded by the bootstrap boot loader. Not the same bootloader = no access.
Cool bootloaders have other security features built in that make it difficult to perform certain types of hacking.
So why three classes of loaders? Because they represent three levels of trust. The most trusted classes are core API classes. Next, extensions are installed, and then the classes that appear on the class path, which means that they are local to your machine.
See Bill Venners Inside the Java Virtual Machine for a more detailed explanation.
source share