Command Line Arguments

Command Line Arguments in Java with Example

What is Command Line Argument?

Command Line Argument is information passed to the program when you run the program. The passed information is stored as a string array in the main method. Later, you can use the command line arguments in your program.

Example While running a class Demo, you can specify command line arguments as

Step 2) Save & Compile the code

Step 3) Run the code as java Demo apple orange.

Java Command Line Arguments

Step 4) You must get an output as below.

Java Command Line Arguments