[Java] ClassLoader loaded

ClassLoader is a class loader, but note that there is ava class loader is not the only one, to create our own class loaders are often inherited ClassLoader. All java class loader total is divided into two sets of categories loader: parents loaded.

DK provides three ClassLoader, according to hierarchy descending order:

    Bootstrap ClassLoader, mainly JVM load the class itself needs work.
    Extension ClassLoader, the main load% JAVA_HOME% \ library classes in lib \ ext directory.
    Application ClassLoader, the main class is loaded Classpath specified library, which is generally in the program default class loader also ClassLoader.getSystemClassLoader () return value. (Classpath where the default refers to the Classpath environment variable configuration, but can be used to modify the -cp parameter when executing commands Java Classpath currently used by the program)

What is a parent to load:

If a class loader loads the class received a request, he first does not own to try to load this class, but this request entrusted to their parent loader, each layer of the class loader is true, so all the final class loading request should be sent to the Bootstrap ClassLoader top, only when the parent loader feedback they can not handle the load request, child loader will try to load it.

If the user-defined classes, use other class loader, such as ExtClassLoader. AppClassLoader, to avoid system security issues.

Why parents to load, if you define a class like java classes and a built-in, such as java.lang.String, then eventually pose a security shake-generation, so the use of parents loading mechanism to ensure the safety of the system.

While using a custom class loader Another benefit may be the source of user-defined class file, the default class loader in the case are sufficient by CLASSPATH load, but if you define your own load , you can load the remote definition.

Guess you like

Origin www.cnblogs.com/guangluwutu/p/12300771.html