GeekInterview.com
Series: Subject: Topic:
Question: 16 of 21

Command Line Arguments

What is Command Line Arguments?
What are its uses?
Where we have to use this?
Asked by: kichha | Member Since Jan-2008 | Asked on: Jul 28th, 2008

View all questions by kichha   View all answers by kichha

Showing Answers 1 - 2 of 2 Answers
abhishekrane

Answered On : Dec 9th, 2008

View all answers by abhishekrane

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.
Abidullah

Answered On : May 21st, 2010

View all answers by Abidullah

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.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Question Categories

Algorithm Questions

ColdFusion Interview Questions

Computer Awareness Questions

Delphi Interview Questions

Perl Interview Questions

PHP Interview Questions

Python Interview Questions

VBA Interview Questions

VoiceXML Interview Questions

XML Interview Questions

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.