Command Line Arguments

During program execution, information passed following a programs name in the command line is called Command Line Arguments.
Example : While running a class Demo, you can specify command line arguments as
java Demo arg1 arg2 arg3 …

Command Line Arguments Important Points:

  • Command Line Arguments can be used to specify configuration information while launching your application.
  • There is no restriction on the number of command line arguments.You can specify any number of arguments
  • Information is passed as Strings.
  • They are captured into the String argument of your main method

Assignment: To Learn Command Line Arguments
Step 1) Copy the following code into a editor







class Demo{

public static void main(String b[]){

System.out.println(“Argument one = “+b[0]);

System.out.println(“Argument two = “+b[1]);



Step 2) Save & Compile the code
Step 3) Run the code as javac Demo apple orange

Step 4) You must get an output as below.



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s