Java 7 searches for the main method before loading the class. This is a behavior change from previous java versions, and therefore your static block is not executing. In previous versions, the behavior was that the JRE used the main method search after loading the class and after executing static blocks.
So, if you run your code on any version prior to java 7, you will see that the static block is executing.
The book you are reading cannot be written for java 7, but the jdk & jre that you use to execute the samples is version 7.
Tip . As a good reading practice, you should try to run sample books in the same version that are listed in the book to avoid confusion. Although in this case, your confusion will force you to learn something new about java 7.
source share