0
  1. Web servers like : Apache Tomcat.
  2. App servers like : Weblogic.
  3. EJB containers.
  4. Android java container. 5> all the other java implementations?
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
santosh s
  • 3,429
  • 2
  • 13
  • 5
  • 3
    All Java programs must start with a main method. Sometimes the method is visible to the programmer, and sometimes (such as with applets), it's not. – Hovercraft Full Of Eels Feb 14 '13 at 03:07
  • It depends what you mean by "Java programs". Applets for example starts with `init`. – Pshemo Feb 14 '13 at 03:14
  • @Pshemo: but that ignores the fact that there is a main method required somewhere, in this situation in the applet launching code, away from programmer's eyes, but regardless, the main *must* be there. – Hovercraft Full Of Eels Feb 14 '13 at 03:15
  • @HovercraftFullOfEels your right. To start JVM we ned to use some variant of `java SomeClass` command which searches for `main` method in that class. – Pshemo Feb 14 '13 at 03:19

6 Answers6

1

Usually yes. But no, it is not required ... as eloquently pointed out by this answer ... https://stackoverflow.com/a/2897323/1481262

Also, while instrumenting the code of applications (using the java.lang.instrument package), the execution starts with the premain method before the main is executed. - [1] [2].

[1] http://docs.oracle.com/javase/6/docs/api/java/lang/instrument/package-summary.html
[2] http://dhruba.name/2010/02/07/creation-dynamic-loading-and-instrumentation-with-javaagents/

Community
  • 1
  • 1
vijay
  • 2,646
  • 2
  • 23
  • 37
0

Yes. When you start a java program, you specify the class to use, and it's static main method is invoked with the command line arguments.

Will Hartung
  • 115,893
  • 19
  • 128
  • 203
0

Yes all java programs begin with main, though it's not necessary for each class to have it's individual main function.

Shobhit Sharma
  • 1,599
  • 13
  • 14
0

Yes, all programs should start with main , It is something like contract between JDK and JRE.

Siva Kumar Reddy G
  • 1,274
  • 3
  • 18
  • 32
0

The JRE always starts from a main() method. However, it is possible to start up a JRE and use it to run several independent programs. For example, a browser will often run all its applets in the same JRE.

Russell Zahniser
  • 16,188
  • 39
  • 30
0

Theoretically, you can write a custom launcher instead of java.exe, like here http://www.codeproject.com/Articles/17352/JVM-Launcher. Take a look at how they invoke main:

//Find the class
jclass    jcJclass = psJNIEnv->FindClass(mainClassName);

//Find the main method id
jmethodID jmMainMethod = 
    psJNIEnv-> GetStaticMethodID(jcJclass, "main", "([Ljava/lang/String;)V");

//Call the main method.
psJNIEnv->CallStaticVoidMethod(jcJclass, jmMainMethod, joApplicationArgs);

that is, it could be any method

Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275