It's not a secret anymore!*
The moose likes Beginning Java and the fly likes String args[ ] in main Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "String args[ ] in main " Watch "String args[ ] in main " New topic
Author

String args[ ] in main

Krishnamurthy Rajagopal
Greenhorn

Joined: Feb 05, 2001
Posts: 2
Hi!
I am new to java and when I analyzed the command line
public static void main(String args[ ]){
I found that any modifier works fine(came to know through java ranch discussions that it is already registered as a bug).I found convincing answers for static and void too. But what bewilders me is why one has to pass String args[ ] parameter in the main method even when one does not make use of it. It makes sense when I am using command line to pass arguments but why should it be made mandatory parameter for all programs. Is there any rationale behind it?
Thanks in advance
krish
Randall Twede
Ranch Hand

Joined: Oct 21, 2000
Posts: 4340
    
    2

They probably didnt want to overload main().
That way the JVM calls the same method for every class.
As you know, you dont have to pass any arguments if they arent needed.
[This message has been edited by Randall Twede (edited February 05, 2001).]


SCJP
Visit my download page
Krishnamurthy Rajagopal
Greenhorn

Joined: Feb 05, 2001
Posts: 2
Hi Randall!
Thanks for the answer.
krish
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: String args[ ] in main
 
Similar Threads
how to read character from command line and store it string
Why it is not 'null' ?
main(String[]args)
parseInt Question.......
Using multiple command line arguments to open multiple files