the explanation is quite in detail but iam abstracting it for this specific question
first of all a class is loaded by the class loader subsystem when it refers to it for the first time in runtime and not compile time.
so the ClassLoader itself is a class in java.lang package and
its instances are called as classLoader instances that load the classes
now coming to details of this it follows an hierarchy with the BootStrap ClassLoader being at the top
note the BootStrap class loader itself is an instance of ClassLoader.
more ever these instances also perform verification ,preparing ,resolving symbolic references to keep it simple it performs dynamic linking of your java program.
now when your compiler compiles .java file it inserts a public static final field of type Class
you can access it in your java.lang.Class obj=name_of_your_class.class
and it contains a method getClassLoader which tell the classLoader Instance that loaded this class.
fine its only by using this information the ClassLoaders get to know the name of the class to be loaded ie its fully qualified name(package.class)
now before searching for a file in its native file system and loading it
it checks with its parent instance that it has already loaded that file nad this checking propagates all the way top BootclassLoader
only if none of them have loaded it then only that instance loads that classfile .
the details of how these things happen is irrelevant in this context.
and once the class is loaded the static block is executed in the initialization phase of class loader subsystem.
since i have already told that its the compiler that plays the role of inserting that field.
and note that not finding main method is an runtime error so the compiler is not responsible for that rather it is the JVM .
from java 7 the main method is searched before and if we dont have we get this error in runtime
but in java 6 and earlier version when class loading had taken place there itself the static block was exectued and then it searched to find the main method but if we provide System.exit(0) ; in the block it terminates the program even before search is made hence we did not have any error
although in java 7 probing for the main method is done before execution of the static block the execution of static block itself depends on the successful finding of main method.even though the order of execution of program is program is same as in java 6 and earlier edition.
further in detail the first element to be placed on the stack itself should be the main thread.
and we know how the execution control flows and its even important to note that static blocks even if they are containing variable local to their block they are never placed as an activation record on the stack but rather on the method area.
so from java 7 the JVM checks for the existence of main thread record on the stack then giving the control to the static blocks after which it executes all the static blocks in its order . whereas it did the reverse in java 6 and earlier edition
its also important to note we cannot nest a static block within any static or non static scope as this block has its only higher enclosed scope to be that of the class
i even know its a bit tricky to understand it but reading this answer will definitely provide a good ,accurate and deep understanding of static blocks .