I have written a simple class with one static block
class Hello
{
static {
System.out.println(\"Hello\");
System.exit(0);
}
}
The program doesn't execute because from JDK 1.7 oracle has put the restriction on static block and static variable calling method if your program doesn't have main method with proper signature but static block and method will always be execute first.As memory management of static variables are done at the time of class loading.
You need to probably put public static void main(String[] args){ }
method in your class for JDK7.
In JDK7, main method's presence is checked before the static block and if it doesn't find one you get the exception.
Java 7 looks for a main method before loading the class. This is a behavior change from previous java versions and hence your static block is not executing. In previous versions, the behavior was that JRE used to look for main method post loading the class and after executing the static blocks.