Analysis of Java Class Loader

Source: Internet
Author: User

Jvm classLoader architecture:

Bootstrap ClassLoader/start class loader
It is mainly responsible for packaging the core api under the jdk_home/lib directory or the jar specified by the-Xbootclasspath option.
Extension ClassLoader/Extension class loader
It is mainly responsible for packaging the jar package in the jdk_home/lib/ext directory or the jar package in the directory specified by-Djava. ext. dirs.
System ClassLoader/System Class Loader
It is mainly responsible for packaging classes and jar files in the directory referred to by java-classpath/-Djava. class. path.
User Custom ClassLoader/User-defined class loader (subclass of java. lang. ClassLoader)
During the program running, the class file is dynamically loaded through the subclass of java. lang. ClassLoader, reflecting the Dynamic Real-time class loading feature of java.
Classloader features:

Each ClassLoader maintains its own namespace. Two classes with the same name cannot appear in the same namespace.
To implement the Class Loader security mechanism at the top layer of the java Security Sandbox Model, java adopts the "parent-delegate loading chain" structure by default.
 

Why is this dual-parent delegation used?

This avoids repeated loading. When the parent has already loaded the class, there is no need for the sub-ClassLoader to load it again.
Considering the security, let's think about it. If we don't use this delegation mode, we can use custom strings to dynamically Replace the types defined in the java core api at any time, this poses a great security risk, and the dual-parent delegation method can avoid this situation because the String has been loaded at startup, therefore, a user-defined class cannot load a custom ClassLoader.
Java dynamically loads class in two ways:

Implicit is implicit, that is, the class is dynamically loaded using the feature loaded only by instantiation.
There are two explicit modes:
ForName () method of java. lang. Class
LoadClass () method of java. lang. ClassLoader

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.