Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How does java know what class to invoke the main() method of?

  1. May 12, 2012 #1
    In C++, pretty much any global main() function gets run. In C#, amy class's Main() method gets run, and having multiple Main() methods in multiple classes should give a compilation error(?). But if we have a .jar, when running it, how do we know which class's main() method the .jar will run?
     
  2. jcsd
  3. May 13, 2012 #2

    chiro

    User Avatar
    Science Advisor

    Hey Whovian.

    Actually for C and C++, you have to provide an entrypoint in many cases for different compilers and the 'main' is not always assumed to be main (although it is set by default to do this).

    As for your question in Java, a quick google search gave this:

    http://docs.oracle.com/javase/tutorial/deployment/jar/appman.html
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook