The life cycle of the Java class and the initialization time of the class

Source: Internet
Author: User

The life cycle of a class isLoading、ConnectionAndInitializeStart, to the end of the class being unloaded.

A Java program can use a class only if it is in its life cycle, such as calling static properties and methods of a class, or creating a real column of a class

Brief introduction

1: Load

The load time of a class refers to reading the binary in the class's. class file into memory, storing it in the method area of the runtime data area, and then creating a Java.long.Class object in the heap to encapsulate the data structure of the class within the method area. It also provides a Java program with access to the data structure interface of the class within the method area.

The ClassLoader of a class does not require a class "first active use" when loading it, and the Java Virtual Machine specification allows the ClassLoader to anticipate that a class will be used, preload it

2: Connect

2.1: Verify

2.2: Prepare

2.3: Parsing

3: Initialize the static variable to the class to give the correct initial value

Unlike loading, Java virtual machines are initialized only when a program uses a class or interface for the first time.

3.1: Create a real column of the class (new, Reflection, clone, serialization)

3.2: Calling a static method of a class

3.3: Access static variables of the class (you can see that the static variable is initialized when the actual column of the class does not exist)

3.4: Initializes a subclass of a class. That is, the initialization of a subclass initializes the parent class (calling the constructor of the parent class), which is why the object class has a default parameterless construction method.

3.5: Subclass of the startup class identified by the Java Virtual machine

Supplemental: Class-loaded Father delegation mechanism

The life cycle of the Java class and the initialization time of the class

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.