The life cycle of the Java class

Source: Internet
Author: User

Reference post: http://www.ibm.com/developerworks/cn/java/j-lo-clobj-init/


It shows the class life cycle flow; In this article, I'm just going to talk about the "initialization" and "Object instantiation" phases of the class.

Class initialization

Class initialization phase, which is the last work in the previous phase of a class or interface being used for the first time, this stage is responsible for assigning the correct initial value to the class variable.

The Java compiler collects all of the class-variable initialization statements and static initializers of the type into the <clinit> method, which can only be called by the JVM and is dedicated to the initialization work.

In addition to interfaces, before initializing a class, you must ensure that its direct superclass has been initialized, and that the initialization process is guaranteed to be thread-safe by the JVM. Also, not all classes will have a <clinit> () method, and the class will not have a <clinit> () method in the following conditions:

    • The class does not declare any class variables or static initialization statements;

    • The class declares a class variable, but does not explicitly initialize it with a class variable initialization statement or static initialization statement;

    • This class contains only class-variable initialization statements for static final variables, and class-variable initialization statements are compile-time-constant expressions.


The life cycle of the Java class

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.