File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/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


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

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: 4397
    
    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: 11351
    
  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.
 
GeeCON Prague 2014
 
subject: Is it possible to have two main methods in one Java Project?