Command Line Arguments in Java

In the standalone application, we need to pass values at the time of execution of our program. We can pass the value as arguments from the command line. These passed arguments can be

To pass the arguments in runtime, run the java program using the following command –
java className agr1, agr2 ,rg3

Here className is the name of the class and after that argument list that we want to send in the program. With the help of args array list of string types, we can take the argument list into our program.

Example:

A simple example to pass the value from the command line –

Note: Run the program on the command line by passing the arguments like this –
java Demo Kapil 29

public class Demo {

	public static void main(String[] args) {

		String name = args[0];
		String age = args[1];

		System.out.println(name + " your age is = " + age);

	}
}
Example Output

Share