Java class Load notes (1)

Source: Internet
Author: User

When a program calls a class and the class is not loaded into memory, our system initializes the class with the following three steps:



1. Loading of classes

Class loading refers to the reading of a class file into memory and creating a Java.lang.Class object for it. Class is loaded by the class loader, we can load binary data from the following sources through the ClassLoader:

--Load the class file from the local file system.

--Load the class file from the jar package.

--Load the class file from the network.

--Dynamically compile and load a Java source file.


2, Class of connection

When the class is loaded, a class object is generated and then the binary data is merged into the JRE. Class joins are then divided into the following steps:

--Verify that the class being loaded has the correct internal structure and is consistent with other classes.

--allocates memory for the static field of the class and sets the default value.

--Replace the symbolic reference in the binary data of the class with a direct reference.



3. Initialization of class

The initialization of a class is primarily initialized with static filed, specifying that static initialization can specify initialization values by declaring a static field, and you can specify initialization values for static field by static initialization blocks.

The initialization of a class is primarily based on the following steps:

--If the class has not been loaded and connected, then the class will be connected before loading.

--When performing the first step, you should check whether the immediate parent class of the class is initialized, and if not initialized, initialize its immediate parent class (of course, when initializing the direct parent class, the immediate parent class has a direct parent class, and the immediate parent class is checked, and so on)

--If there are initialization statements in the class, then execute the initialization statements in turn.




Reprint Please specify source: http://blog.csdn.net/hai_qing_xu_kong/article/details/42609883 Emotional Control _  

Java class Load notes (1)

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.