It is actually possible to run an app without a main method, for example:
Code:
public final class NoMainMethod {
static {
System.out.println("I have no main method, but can still do stuff!");
System.exit(0); // required to stop NoSuchMethodError
}
}
Run like so:
This works because when the class is loaded, the contents of the static initializer are executed by the class loader. Then it quits the application to prevent the NoSuchMethodError from being shown. However, I wouldn't recommend doing this!
If you are developing an applet, your app won't have a main method. Instead, you subclass applet and specify the the applet to load in the <applet> tag. However, ultimately, somewhere along the line there is a main() method (or that nasty trick, unlikely to see that in production code though) which then goes and calls the appropriate applet method.
There are probably other situations where you won't have a main() method, e.g. if you are writing an app to instrument another app you'll have a premain() method instead. If you are writing a J2EE app, you'll just have a collection of servlets (and some convoluted xml files defining them). Kind of like the applets, another program (the application server) starts it for you.