Java class loading notes (1), java class loading notes

Source: Internet
Author: User

Java class loading notes (1), java class loading notes

When a program calls a class that has not been loaded into the memory, our system will initialize the class through the following three steps:



1. class loading

Class loading refers to reading the Class file of the class into the memory and creating a java. lang. Class Object for it. The Class Loader loads binary data from the following sources:

-- 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 connection

After the Class is loaded, the system generates a Class object and then merges the binary data into the JRE. The class connection is divided into the following steps:

-- Check whether the loaded class has a correct internal structure and is consistent with other classes.

-- Allocate memory for the static Field of the class and set the default value.

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



3. class initialization

Class initialization mainly initializes static Filed. To specify static initialization, you can specify the initialization value by declaring the static Field, or you can specify the initialization value by using the static initialization block as the static Field.

Perform the following steps to initialize a class:

-- If this class has not been loaded and connected, load it first and then connect it.

-- When performing the first step, check whether the direct parent class of the class is initialized. If no Initialization is performed, initialize its direct parent class first (of course, when initializing the direct parent class, this direct parent class has a direct parent class, and check its direct parent class, and so on)

-- If there are initialization statements in the class, execute these initialization statements in sequence.




Reprinted please indicate the source: http://blog.csdn.net/hai_qing_xu_kong/article/details/42609883 sentiment control _

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.