This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes Is it possible to have two main methods in one Java Project? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Is it possible to have two main methods in one Java Project?" Watch "Is it possible to have two main methods in one Java Project?" New topic
Author

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

Varuna Seneviratna
Ranch Hand

Joined: Jan 15, 2007
Posts: 167
Is it possible to have two main methods in one Java Project?


Varuna Seneviratna
Singh Harmeet
Ranch Hand

Joined: Aug 05, 2011
Posts: 115

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........


With Regards :-
Harmeet Singh
Ninad Kulkarni
Ranch Hand

Joined: Aug 31, 2007
Posts: 787

Hi Varuna,
When you run java program from command line main method is entry point. There is no restriction for main method.


SCJP 5.0 - JavaRanch FAQ - Java Beginners FAQ - SCJP FAQ - SCJP Mock Tests - Tutorial - JavaSE7 - JavaEE6 -Generics FAQ - JLS - JVM Spec - Java FAQs - Smart Questions
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4344
    
    8

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

Joined: Oct 02, 2003
Posts: 11172
    
  16

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.
 
subject: Is it possible to have two main methods in one Java Project?
 
Similar Threads
main method
public static void main - Been on my mind
Is there succint Eclipse setup HOWTO for compiling java?
Calling a method from the command prompt
can there be more than one main method in a java program