-2

A friend of mine told me that in java, there is a main group which in-turn has a main thread and this thread contains a main method.

But he wasn't able to explain me how the main thread is invoked by JVAM. Could any one explain how this is implemented by JVM. I have tired searching for an answer of this in Google but that did not yield any good result.

User27854
  • 824
  • 1
  • 16
  • 40
  • 5
    Check this out: http://stackoverflow.com/questions/4446542/how-does-the-jvm-use-the-main-method-to-start-a-java-program – Ruchira Gayan Ranaweera Feb 10 '14 at 04:59
  • 4
    Your friend seems to have been just guessing, or answering a different question. – user207421 Feb 10 '14 at 05:00
  • Hmm what can i say.. @RuchiraGayanRanaweera Thanks for your link. I am going through it.. – User27854 Feb 10 '14 at 05:09
  • The runtime instance of a JVM's function is to run one java application and when the application completes,the instance dies. When you give 'java Example' in the console, the operating system executes the java SDK and the Example is the name of the initial class.The main() method of an application's initial class serves as the starting point for that application's initial thread. – amudhan3093 Feb 10 '14 at 05:17
  • Its so pathetic that people vote down at there whims and fancy, without going through links. The link given does not give any detailed explanations as how the main method is invoked by JVM. To summarise it tells that the main method is just and entry point and the JVM looks for a method method signature main(string[] args) etc.. – User27854 Feb 10 '14 at 05:25
  • @amudhan3093 I do understand that main is the starting point and jvm looks for main to start an execution. Anyways thanks for your time and effort.. I got a link which details, about the implementation in the above.. http://stackoverflow.com/questions/17432963/how-main-thread-created-by-java – User27854 Feb 10 '14 at 05:30

1 Answers1

3

It's not a main thread, it's a main method. Of course, all methods have to be run in a thread; the JVM specially creates a thread, informally called the main thread, to invoke the main method.

All software needs a special-cased entry point that the host system (that runs the software) knows about. In Java, it's the main method, as specified in JLS 12.1.

So basically, the "how does it know" is that the people who wrote the JVM put special code in that looks for a public static void main(String[]) method and starts it on a thread created for that purpose.

yshavit
  • 42,327
  • 7
  • 87
  • 124