I. Purpose of the STATIC keyword
You can make (method/variable) calls without creating an object. That is, a method or variable modified by the static keyword does not have to rely on an object for access, so long as the class is loaded, it can be accessed by the class name.
1,static Modification Method
Static methods are commonly referred to as static methods, and because they can be accessed without relying on any object, there is no this for static methods because it is not attached to any object, and since there are no objects, this is not the case. And because of this feature, non-static member variables and non-static member methods of the class cannot be accessed in a static method, because non-static member methods/variables must be dependent on a specific object to be able to be called. Of course, the static member method/variable can be accessed in a non-static member method.
2,static modifier variables
Static variables are also known as static variables, except that the static variables are shared by all objects, only one copy in memory, and are initialized only when the class is first loaded. Instead of static variables, which are owned by an object, are initialized when the object is created, there are multiple copies, and the replicas owned by each object do not affect each other. The initialization order of static member variables is initialized in the order in which they are defined.
3,static Modifying code blocks
Another key function of the static keyword is to form a static block of code to optimize the performance of the program, because the static code block is only executed once when the class is first loaded. A static block can be placed anywhere in the class and can have more than one static block in the class. When the class is first loaded, each static block is executed in the order of the static blocks and is executed only once.
Two. Considerations for the Static keyword
The 1,static keyword does not change the access rights of members in the class, that is, the visibility and scope of the members . The only private, public, protected (including package access rights) keywords that can affect access in Java.
2,static cannot act on local variables for unknown reasons, and may not be necessary for Java.
3, class loading is to load the parent class and then load the subclass, but it also means that the static code block of the parent class is executed before the static code block of the subclass.
Concluding remarks: How lazy are you?! Why don't you just compile a Java program? You know, running?
Java re-learning-delve into the static keyword