Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

main argument  RSS feed

 
Thiagu Gopal
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why string arg[] is need for main method when not give any command line argument ?
ex:
int add()
here add method with null argument
so similarly we can write main method
 
Shaan Shar
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Thiagu Gopal:
Why string arg[] is need for main method when not give any command line argument ?
ex:
int add()
here add method with null argument
so similarly we can write main method


Yes you can right but think one scenerio when you need to pass some run time parameter from user and you cann't use IO API's.......

Tell me in this situation what you will do...

 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why string arg[] is need for main method when not give any command line argument ?
Because that's just the way the inventors of Java have specified it. The main method must always look like this:

If it would be allowed to write the main method without parameters, it would only make things more complicated. For example, you would be able to write a class with two main methods:

Which of those should be executed? Do you think the Java runtime environment should call the one without parameters if you don't specify parameters on the command line, and the other one otherwise?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!