File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Concerns regarding the main method Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Concerns regarding the main method" Watch "Concerns regarding the main method" New topic

Concerns regarding the main method

Subhashish Pattnaik

Joined: Nov 07, 2010
Posts: 14
Dear Ranch members, i have had a doubt regarding the overloading of main method in JAVA.

Am not quite sure of this theory in particular and would definitely seek a help from you !!

Is it possible to overload the MAIN method in java??
My apologies if am falling short of some explaination here.


Subhashish Pattnaik
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15094

Yes, the main method is just like any other method, so you can also overload it just like any other method.

However, the JVM will only look for a specific version of the main method that is public, static and void and takes a String[] argument. You can create other methods called main, but these cannot be used as the entry point of your program.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Subhashish Pattnaik

Joined: Nov 07, 2010
Posts: 14
Many thanks Jes!!

Can you help me out by an instance of short example. That should help me understand better !!

Hope the master helps me out.

fred rosenberger
lowercase baba

Joined: Oct 02, 2003
Posts: 11955

there's not much to it...Why don't you try doing it yourself first, and post your attempt here.

Write a class with a "public static void main(String[] args)" method. Then write another main method, with a different argument list. see if it compiles. See if you can get the non-standardly defined one to run from the command line. (hint - you can't).

There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Aditya Jha
Ranch Hand

Joined: Aug 25, 2003
Posts: 227

Another twist to the tale... if you're using JDK 5 or above (which you must be, unless you're stuck with some legacy code), try:

Just for fun! Try to guess if it compiles and/or runs.
I agree. Here's the link:
subject: Concerns regarding the main method
It's not a secret anymore!