0

Is their any other use of "String args[ ]" in main method?

Is their any other use of using String args[ ] parameter in main method except for accepting arguments from command line. If their are any please do elaborate about it.

7th Feb 2017, 10:53 AM
Ratnadeep Dey
Ratnadeep Dey - avatar
2 Answers
+ 16
It is used to get command-line arguments and nothing more.
7th Feb 2017, 11:02 AM
Igor Makarsky
Igor Makarsky - avatar
+ 1
Receiving arguments in the main method is mostly done when utilizing the command line, but that isn't the only way they can be used. For starters lets think about what the command line actual is. In windows it's usually a program called CMD or command. In linux and mac it is usually the terminal or a bash shell. All of which are actually just programs themselves. Also, If you have ever used a good IDE you can specify the main arguments usually somewhere in your project. Your IDE is yet just another program. So, in reality what is really happening is that another program is passing these arguments to the main method of your program. So yes you can in fact call another program, with some predefined arguments, from your program, much like calling a function in some cases. EDIT: Here is an example of the above http://stackoverflow.com/questions/7800090/passing-values-from-one-java-program-to-another It's also possible to utilize the main method from within your own program calling it and passing it a new String array and then doing some work and returning.
7th Feb 2017, 12:04 PM
ChaoticDawg
ChaoticDawg - avatar