The static keyword can be used to modify variables, methods, code blocks, and inner classes.
Static resources from the point of view of the class loading mechanism of the JVM, it is loaded into the method area when the class is first initialized, and non-static resources need to be loaded into the stack when the class new object is created. For example, using the Class.forName ("xxx") method to initialize a class to load a static resource, as well as ensuring that the class is initialized before the new object is created.
Static variable:
Static variables are shared by all objects and have only one copy in memory. Therefore, when the static variable is modified by an arbitrary object, it affects all objects.
(PS: You need to pay more attention to the use of shared resources in multiple threads.) )
static method:
The idea of Java programming says that static methods are not the method of this. Instead of static methods and variables need to be accessed through objects (this), only static variables can be referenced inside static methods. Non-static methods can refer to non-static variables, static methods, and static variables inside.
static methods and static variables can be accessed directly through the class name, i.e., the class name can be used to find the class information in the method area.
(PS: See why the static method does not have this by Javap–verbose Xxx.class.) The default non-static method parameter list is automatically added with the This parameter. This represents the current object, so this can access all static non-static methods and variables)
Static code block:
A static block of code, like a static variable, executes when and only when the class is first initialized. The order in which static resources are loaded is loaded in the order in which they are defined.
Note: Static code blocks can be assigned to static variables after it is defined, but cannot be accessed
Static Inner class:
For static internal classes, refer to the following internal class articles
Static import:
Static import: Must be written as import static, cannot be written as static import
Benefits: Simplify some operations, improve readability, and use static methods without writing corresponding class names
Resources:
Http://www.cnblogs.com/xrq730/p/4820992.html
Http://www.cnblogs.com/dolphin0520/p/3799052.html
http://lavasoft.blog.51cto.com/62575/18771/
==================================================================
This is I read other people's blogs, self-study and summed up after the blog post, I can guarantee that every word here is I carefully after careful consideration of the written down, but also welcome to point out the problem of the place. I hope to stand on the shoulders of giants to share knowledge with everyone.
"If I look farther than others, it is because I stand on the shoulders of giants"--Newton
==================================================================
First, the static key of the Java Foundation