Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8014633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:59:56+00:00 2026-06-04T19:59:56+00:00

Why does the main method in Java always need arguments? Why should we write

  • 0

Why does the main method in Java always need arguments? Why should we write String[] args every time, instead of just writing it when we use any arguments?

A method like this generates Main method not found compiler error. Since we never use any arguments to the main method, this should be allowed.

public static void main()
{
}

This is not an interview question. It just came to my mind while programming.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T19:59:58+00:00Added an answer on June 4, 2026 at 7:59 pm

    Basically, there are four answers:

    1. Because that’s the way it was designed. Yea, I know that’s a circular reason. But the point is that this is the way it is and it ain’t going to change. So unless you are planning on designing your own language, the question is moot.

    2. Cleanness of design (aka the DRY principle). Don’t specify two entry point signatures when one can do the job. And clearly, it can.

    3. Semantic simplicity. Suppose (hypothetically) that Java did support both void main(String[]) and void main() entry points. What would happen if a class defined both methods? Is that an error? If not, which one takes precedence when there is ambiguity? Is this confusing yet?

      By only recognizing void main(String[]), the JLS avoids that problem1.

    4. This is analogous to the standard C and C++ entrypoint signatures. (Admittedly, some C / C++ runtimes support other non-standard entrypoints as well, but that’s not exactly a good thing2.)

    None of this means that it would have been unambiguously wrong to do it another way. And for example C# gives you alternative signatures, and deals with the ambiguity problem by requiring the developer to designate an entry point some other way.

    FWIW, this wikipedia page describes the "main" method in a number of languages.


    1 – Though then you have the "problem" that people who are new to Java might guess (incorrectly) that multiple entry points ought to work, try it, and get a surprise. But I don’t think any design could cope with "programming by guesswork".

    2 – For a start, it is a portability issue.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Consider a main method: public static void main(String[] args) throws Exception { System.out.println(property=' +
The following code gives an unreachable statement compiler error public static void main(String[] args)
main is not a keyword in java. How does the JVM know to execute
If i have this in my main method: PrintWriter output = new PrintWriter(new FileWriter(args[1]));
Does the following code run on the main thread? Does main queue refer to
Does the main function we define in C or C++ run in a process
Does this code cause a memory leak: int main(){ int * a = new
Why does the execution of TestClass.main() outputs 202 202 101?? class BaseClass { int
On my main page I have this jquery code which does an ajax call
Why does the following code seg fault before returning: int main() { char iD[20];

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.