Command Line Arguments

What is Command Line Arguments?
What are its uses?
Where we have to use this?

Questions by kichha   answers by kichha

Showing Answers 1 - 2 of 2 Answers

command line arguments are those which can be passed to the main method as parameters and use those values in the main method before executing it.

  Was this answer useful?  Yes


  • May 21st, 2010

Command line arguments are used to provide input through console to the main function. The inputs values generally store into a string array (usually args[])

void main (String args[])
for (int i=0; i<args.length; i++)
print args[i]

for the program above if complied with a name "program", can be executed like,

directory:> program argument1 arg2 arg 3
in this case it will have 4 arguments.

because the argument values are assumed to be separated by space.

Some compliers support quotation marks to enclose space key e.g "arg 3" would be a single argument because its enclosed in quotations marking the start and end of string.

Remember  command line args are always only strings. If a numeric value is passed as an argument it would have to be explicitly type-casted/parsed/converted from string to a numeric value.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.


Related Answered Questions


Related Open Questions