Hi Anil,
Every Java application begins with execution of an main method (even
applets and
servlets - it's just that the main method is hidden in the container), and therefore the code you supplied won't run without a main method - in fact if you type ">java WithoutMain" you will get a "Missing main method" exception.
The example you may have been referring to is as follows:
If you compile and run this code you will see the output "Hello World", but you will notice there is no code in the main method - the output occurs because every time a class is loaded into memory by the JVM (and I don't mean an object of a class being instantiated, just that the JVM inspects the class definition) any static initialiser blocks will execute.
This is why we see the output above - The JVM loads the class into memory (because it has to in order to execute the main method), the static initialiser block runs (printing output), and then the main method would run (which in this example would do nothing), except that the "System.exit(0)" terminates the program. That's all System.exit(0) does - it immediately stops execution of the program returning the value in the brackets to the operating system (0 is considered normal termination in unix, and -1 or 1 abnormal condition, such as a fatal error the program cannot recover from)
I hope this helps.
Daniel
[ August 03, 2006: Message edited by: Daniel Bryant ]