This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is it possible to have two main methods in one Java Project?

 
Varuna Seneviratna
Ranch Hand
Posts: 169
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to have two main methods in one Java Project?
 
Singh Harmeet
Ranch Hand
Posts: 115
Eclipse IDE Java Tomcat Server
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes it is possible, because main is also a user define method , but its defenation is define in jvm and this method is call by jvm like simple methods call........
 
Ninad Kulkarni
Ranch Hand
Posts: 802
Hibernate Linux Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Varuna,
When you run java program from command line main method is entry point. There is no restriction for main method.
 
Matthew Brown
Bartender
Posts: 4549
8
Java Netbeans IDE Scala
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can have as many as you like (as long as they aren't on the same class). The class you want to execute the main method on is specified as part of the execution command (unless you've created an executable Jar file, in which case it's specified in the manifest file).
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12019
25
Chrome Java Linux
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matthew Brown wrote:You can have as many as you like (as long as they aren't on the same class).

i think you can have more than one main method in a class, as long as they have different signatures - just like any other method.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic