| Java FAQ | ||
| JSP FAQ | ||
| Servlet FAQ | ||
XyzWs Java FAQ:
Can a Java application run without a main method?
Printer-friendly version |
Mail this to a friend
|
Advertisement
|
Can a Java application run without a main method?Yes, you can but do not count on it when you develop your application. In Java, a static initializer gets executed as soon as the class is loaded, even before the main method is called. Here is an example,
public class WithoutMain {
static {
System.out.println( "Hello World" );
System.exit(0);
}
}
The JVM finds and loads the class into memory when you run this code, the static
initializer is executed during the loading and
initialization of the class.
|