Static is a non access modifier. The static keyword belongs to the class rather than instance of the class. Therefore static members are called class members and gets created and initialized at the time of class loading.
The static keyword in the Java can be used to execute some code without creating an object.
The static keyword is considered as class level and is applicable for
Nested classes
The static keyword cannot be used with:
Class (Not Nested)
Constructor
Interfaces
Inner Classes(not nested)
Inner Class methods
Instance Variables
Local Variables
The static variables get one time memory allocation and maintain a single copy for a class which can be shared by all the objects of the class. Therefore the static variables make program more memory efficient.
Static variables will be created at the time of class loading and destroyed at the time of class unloading. Hence the scope of the static variable is exactly same as the scope of the class.
For more details about the static variable visit static variables or class variables
Rules and Uses of Static Initializer Block in Java With Example. Static block also called initializer block is mostly used for changing the default values of static variables. The static block gets executed when the class is loaded in the memory.
For more details about the static blocks visit static block in java
A method declared with static modifier is called static method. The static methods are class level members therefore we can call the static methods using class name.
For more details about the static method visit static method
A nested class declared with static modifier is called static class.
The static classes are the static members of outer classes. The static classes cannot access non static members of outer classes.
Note: You cannot declare outer(non nested) class as static, it is not allowed