Win a copy of Functional Reactive Programming this week in the Other Languages 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: 170
  • 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
  • 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
Java Linux
  • 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: 4568
9
  • Likes 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
Posts: 12198
35
Chrome Java Linux
  • Likes 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic