The main method is not needed in java programs. As others have pointed out, web applications do not use the main method.
It is not even needed in standalone applications. Consider
class JavaAppWithoutMain
{
static
{
System . out . println ( "Hello World!" ) ;
}
}
I compiled it and ran and obtained the following result:
Hello World!
Exception in thread "main" java.lang.NoSuchMethodError: main
For standalone applications you must either have
- a main method or
- a static initializer.
Main is preferred.