Java Tutorial 12 – 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.

