Loaders such as Java 27-1 reflection

Source: Internet
Author: User

When it comes to reflection, first say the ClassLoader of the class.

Classes are loaded: 

When a program wants to use a class, if the class has not yet been loaded into memory, the system initializes the class by loading, connecting, and initializing three steps.

  load :

This means reading the class file into memory and creating a class object for it.

When any class is used, the system creates a class object.

  Connection :

Verify that you have the correct internal structure and that it is consistent with other classes

Prepare to allocate memory for static members of the class and set default initialization values

Resolve to replace a symbolic reference in a class's binary data with a direct reference

  Initialize :

Is the initial steps we've talked about before.

Class initialization time:

    1. To create an instance of a class
    2. Access static variables for a class, or assign a value to a static variable
    3. To invoke a static method of a class
    4. Use reflection to force the creation of a Java.lang.Class object for a class or interface
    5. Initializes a subclass of a class
    6. To run a main class directly using the Java.exe command

Class Loader:

  responsible for loading the. class file into the inside and generating the corresponding class object for it . Although we do not need to care about the class loading mechanism, we understand this mechanism and we can better understand the operation of the program.

The composition of the class loader:

    1. Bootstrap ClassLoader Root class Loader
    2. Extension ClassLoader Extension Class loader
    3. Sysetm ClassLoader System Class Loader

The role of the class loader:

A:Bootstrap ClassLoader root class loader

Also known as the Boot class loader, which is responsible for loading Java core classes

such as system,string and so on. In the Rt.jar file under the Lib directory of the JRE in the JDK

B:Extension ClassLoader Extension class loader

Responsible for loading the jar packages in the extended directory of the JRE.

The Lib directory of the JRE in the JDK under the EXT directory

C:Sysetm ClassLoader System class loader

Responsible for loading the class file from the Java command when the JVM starts, and the jar package and classpath specified by the CLASSPATH environment variable

With these descriptions we can know who is doing the loading of the things we use. So far we've learned to load the class file into memory, so how do we use the contents of these class files if we just stand in the angle of these class files?

Loaders such as Java 27-1 reflection

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.