Initialization and class loading

Source: Internet
Author: User
Tags class definition

In many traditional languages, programs are loaded as a one-time part of the startup process. The subsequent initialization, and then the formal execution of the program. In these languages, the initialization process must be carefully controlled to ensure that the initialization of static data does not cause trouble. For example, when a static data is initialized, another static data is expected to be a valid value, which can cause problems in C + +.

Java does not have such a problem, because it uses a different load method. Because everything in Java is an object, many activities become simpler, and the problem is one example. As the next chapter will cover, the code for each object exists in a separate file. The file is not loaded unless you really need the code. In general, we can assume that unless an object of that class is constructed, the code is not actually loaded. Because of the subtle ambiguity of the static method, it is also considered that "class code is loaded at first use."

The first place to use is also where static initialization occurs. When loaded, all static objects and static code blocks are initialized in their original order (that is, the order in which they are written in the class definition code). Of course, static data is initialized only once.

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.