java-class Loader

Source: Internet
Author: User

1. Class Loader

    • The ClassLoader is used when the program is running to use a class, and the class loader loads the bytecode of that class into memory for execution.
    • Java Virtual machines can install multiple classloader, the system defaults to three main class loaders, each class loader is responsible for loading classes in different locations
    • Bootstrap,extclassloader,appclassloader.
    • Some ClassLoader are also Java classes , so there must be a non-Java class loader to load other Java class ClassLoader, this is boostrap.
    • All ClassLoader in a Java Virtual machine are organized in a tree structure with a parent-child relationship . Each instantiation of a class loader object must be specified for it
    • A parent class loader object, or the system default class loader as the parent.

2.ClassLoader

Construction Method:

ClassLoader ()/////Use the getSystemClassLoader() ClassLoader returned by the method to create a new class loader that will act as the parent ClassLoader.

ClassLoader (ClassLoader parent);//Specifies the Parents class loader, the parent class may eventually call Bootstrap as the last parent.

Member Methods:

ClassLoader getParent ();//returns the parent class loader for the delegate.

Static ClassLoader Getsystemclassloader ();//Return to the System class loader

Class<?> loadclass (String name);//Use the specified binary name to load the class.

3. The relationship of three types of loaders and the scope of the load class

BootStrap: Common Java classes, such as collection classes under System,util, and so on.

Extclassloader: We can export our custom classes to the folder of the ClassLoader,

4. Delegate mechanism of class loader

When the class loader loads the class, it delegates the parent loader to find the class and loads the class, and the parent class is then delegated to the parent class until the ancestor loads the class .

Ancestors did not load into the class, will let the next level to find, until the original delegate loader . If you don't, you're going to report an anomaly. classnotfoundexception

    • The class loader () of the current thread is first getContextClassLoader() loaded to load the first class in a thread.
    • If Class A refers to a class B,java, the virtual machine uses the class loader that loads class A to load Class B.
    • You can also call the Classloader.loadclass () method directly to specify a class loader to load a class.

java-class Loader

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.