Speaking of the keyword static, the first thought of the constant, static variables, this article I summed up the use of static.
1. Static variables
Can be assigned for easy class access.
2. Static method
Both static and static variables can be modified by private and public.
When the JVM loads a class, it loads the static and static variables of the class into the method area. and is only loaded once, shared with all threads, and other threads can change static variables in the method area.
Static final can modify variables and methods to indicate that constants cannot be modified, that methods are not overwritten, and can be accessed through the class name.
3. Static code block
When the JVM loads a class, the static code block runs only once. Because it is loaded into the heap memory first, and the constructor of the class is loaded at new, the constructor runs after the static code block
Non-static variables and non-static methods are not directly accessible inside static code blocks. You can call a method or assign a value to a variable of its class by instantiating the class of the method.
4, there is an internal class called Static inner class
Static inner classes do not need to rely on external classes, and non-static inner classes must hold references to external classes.
5, static Guide package, import static. Simplify the code.
Java's static understanding