Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The process of loading the Java class

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article mainly explains "the loading process of Java class". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn the "Java class is loaded process" it!

The static modifier indicates static, and Jvm puts it in the method area when the class loads, which is shared by the class and all instances of the class. The memory allocated after compilation will remain until the program exits memory and this space will not be released. If a method shared by all instances is declared static, then space can be saved without each instance being allocated to memory during initialization.

The process of loading the Java class:

The class loader loads a class into the Java virtual machine through three steps:

1. Load (generate Class objects in binary form)

two。 Links (subdivided into validation, preparation and parsing)

Check: check the correctness of the binary data of the imported class or interface

Prepare: allocate and initialize storage space to static variables of the class

Parsing: converting symbolic references to direct references

3. Initialization (static variables and static code blocks of the activation class, initialization Java code)

Static variable

Static method

Static code block

A static code block is a set of statements to be executed when a class loader loads an object. Static blocks are executed only once when the class is loaded into memory, and the location can be placed at will. If there are multiple static blocks, JVM will execute them in the order in which they appear in the class, and each block will be executed only once.

Static {/ / is used to initialize resources when the class is loaded, and can only access static variables and static methods System.out.println ("StaticExample static block");}

Static class

A static class can only be defined in an inner class, and a static inner class is bound to an outer class, even if no object of the outer class is created. The methods of static classes can be static or non-static, static methods can be called through static classes, while non-static methods can only be called after creating an object of the class. You can only reference static member variables of external classes (that is, class variables), of course, as long as the visibility requirements of modifier keywords (public, etc.) are met.

If an inner class is not defined as a static inner class, it cannot be defined as static when defining member variables or member methods.

Public class OuterClass {public static class InnerClass {InnerClass () {System.out.println ("static inner class");}} at this point, I believe you have a deeper understanding of the "Java class loading process". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report