As you have already learnt, the initialization expressions of the fields and the code of the constructor methods are used to initialize the objects. A class contains a class initialization method. Though they are both the same, there is only one difference. The class initialization method needs to be explicitly defined in the body of this method. You can write arbitrary codes for initializing the class fields in the Java programming language. This is done using a construct known as a static initializer.
A static initializer is nothing but the keyword static followed by a block of code enclosed in curly braces. This keyword can appear in a class definition wherever a field or method definition appears. A class can use multiple initializers where the body of each initializer is contained into the class initialization method. The initializer’s body also contains the static field initialization expressions. A static initializer is similar to a class method. However, it cannot make use of the this keyword, any instance fields or instance methods of the class. Continue reading JAVA – Initializer blocks