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.
Login to rate this answer.
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[])
Example:
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.
args[0]=argument1
args[1]=arg2
args[2]=arg
args[3]=3
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.
Login to rate this answer.