I have the following simple hello world in Java:
class A {
static {
System.out.println(\"Hello world\");
}
}
It works as ex
When your class is loaded, static initializers will be run, and then the JVM will try to invoke the main method. You can fix this by adding one more line to your static initializer:
public class HelloWorld {
static {
System.out.println("Look ma', no hands!");
System.exit(0);
}
}
This will stop the JVM before it tries to invoke your main method.
Also note, this will not execute in Java 7. Java 7 looks for a main method before initializing the class.