The relationship of three class loaders in Java and the scope of the classes that are loaded separately

Source: Internet
Author: User

Java in the need to use the category when the class is loaded, Java class loading is by the class loader (class loader) to achieve, preset, after the program starts, there will be three categories loader: Bootstrap loader, Extclassloader and Appclassloader.

Bootstrap Loader is written by C + +, The default is to search for the classes or LIB directory in the directory where the JRE resides. The jar file (for example, Rt.jar) has a specified category and is loaded (actually specified by the system parameter Sun.boot.class.path); The preset extclassloader is responsible for searching the directory where the JRE resides. The classes or. jar in the Lib/ext directory has the specified category and is loaded (actually specified by the system parameter Java.ext.dirs); Appclassloader searches Whether the specified classes is in the Classpath and is loaded (specified by the system parameter Java.class.path).

The Bootstrap Loader is loaded after the JVM is booted, and then it loads the Extclassloader and sets the Extclassloader's parent to Bootstrap Loader, The Bootstraploader then loads the Appclassloader and sets the Appclassloader parent to Extclassloader.

When a category is loaded, each class loader first takes the task of loading the category to its parent, and if the parent cannot find it, it is the responsibility to load it, and if he cannot find it, it will throw out the noclassdeffounderror.

After each class is loaded, there is a class instance to represent it, and each class instance remembers which ClassLoader loaded it, and the class's getClassLoader () gets the ClassLoader to load the class.

The relationship of three class loaders in Java and the scope of the classes that are loaded separately

Related Article

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.