how jvm calls the main method

Can any body tell me what exactly happens if I run the command "java MyClass"

where MyClass contains the main method. What are the steps that jvm follows to be able to invoke the main method. It will be better if any related article or siteis mentioned on this subject as I am eager to know in detail.

Thanks in advance.

[339 byte] By [maitya] at [2007-11-26 22:34:02]
# 1

what possible value would that knowledge have? exact details will vary from JVM to JVM, but the crux of it is, it loads the class specified (MyClass in your example) and looks up a public static method called "main", with a return type of void, that takes an array of Strings as its sole parameter. then it creates a new thread and starts it off executing at the start of this main method. this is done largely in native code

no, that doesn't mean that calling main creates a new thread

georgemca at 2007-7-10 11:41:36 > top of Java-index,Java Essentials,Java Programming...
# 2
thanx for ur reply, but i would like to know more. it would be great if u can give me some links where I can find more information on the subject.
maitya at 2007-7-10 11:41:36 > top of Java-index,Java Essentials,Java Programming...
# 3

what more? what exactly is it you want to know? "how jvm calls the main method" was answered above. anything more specific will involve either the source code of a particular JVM, or an understanding - at hardware level - of how code is executed in memory. but there's really no point, the knowledge hasn't got any practical use, and isn't really comprehensible, except to people who wouldn't have to ask such a question in the first place!

georgemca at 2007-7-10 11:41:36 > top of Java-index,Java Essentials,Java Programming...
# 4

What specifically do you want to know? "What happens when the VM invokes main?" is a very broad question with many possible aswers. If you can't be more specific , then the only ssible answer would be to explain the whole process. I guess the VM spec would be the best place to answer that.

http://java.sun.com/docs/books/jvms/second_edition/html/VMSpecTOC.doc.html

jverda at 2007-7-10 11:41:36 > top of Java-index,Java Essentials,Java Programming...
# 5

well, i want to know the steps or phases the jvm goes through from invoking the command java MyClass up to the start of execution of the main method. Like, loading of byte code by class loaders, then verification of byte codes etc. i have some ideas but i would like to know in detail. I am not saying that I want to know how byte code is translated,

but at least want to get some overview.

maitya at 2007-7-10 11:41:36 > top of Java-index,Java Essentials,Java Programming...
# 6

Did you follow jverd's link to the JVM spec? 5.2 "Virtual Machine Startup" and 5.3

"Creation and Loading" seem particularly relevant.

You might also want to have a look at 12 "Execution" in the JLS

http://java.sun.com/docs/books/jls/third_edition/html/j3TOC.html

The more general process of class loading is dealt with in a developerworks

series: http://www-128.ibm.com/developerworks/java/library/j-dyn0429/

pbrockway2a at 2007-7-10 11:41:36 > top of Java-index,Java Essentials,Java Programming...