Learn more about Java Virtual machine---class loading mechanism----initialization phase

Source: Internet
Author: User

The preparation stage is the initial value of assigning the system to the variable. And the initialization stage is to assign the programmer's own value to the variable.

The initialization phase is the execution process of the <clinit> () method. The process is as follows

1. The editor collects all assignment actions and static block merge formation <clinit> methods. The collection is determined in the order in which the code appears. and static initialization blocks can only access variables that are defined in the previous variable, for variables that are then assignable, but not accessible

2. The <clinit> method of the parent class is executed before the <clinit> method of this class is executed. And no explicit invocation is required, and the virtual opportunity guarantees that the parent class <clinit> method executes first. The first <clinit> method performed by a virtual machine is java.lang.object

Note: Classes without assignment operations and static initialization blocks do not have a <clinit> method

In addition to classes, there are interfaces. An interface can have an assignment. operation. But the difference is that you do not need to do the parent interface <clinit> method, only after the use of the execution (a bit like lazy loading)

Learn more about Java Virtual machine---class loading mechanism----initialization phase

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.