aspose file tools*
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 Java 8 in Action this week in the Java 8 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: 784

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: 4244
    
    7

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: 10925
    
  12

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