static block

static block gets executed before constructor is invoked.
static block is executed only once, whether one or more than one object is created.
As shown in below example more than one static block can exist in a class. They get executed in the order in which they are written.
Also non static block can exist in a class. A non static block gets executed once for every object, unlike static block.

static and non static block example:

class TestMe{
	{
		System.out.println("This is simple block");
	}

	static {
		System.out.println("in static block 1 TestMe");
	}

	static {
		System.out.println("in static block 2 TestMe");
	}

	TestMe()
	{
		System.out.println("in TestMe()");
	}
}

public class StaticBlockDemo {

	static{
		System.out.println("in static block StaticBlockDemo");
	}
	public static void main(String[] args) {

		System.out.println("in main program");

		//static block is executed before constructor is invoked
		//static block is executed only once, whether one or more than one object is created
		TestMe tm = new TestMe();
		TestMe tm1 = new TestMe();
		TestMe tm2 = new TestMe();
	}

}

Output:
in static block StaticBlockDemo
in main program
in static block 1 TestMe
in static block 2 TestMe
This is simple block
in TestMe()
This is simple block
in TestMe()
This is simple block
in TestMe()