Command Line Arguments in Java

The array argument in the main() method indicates that you can pass command line arguments to it. You provide command line arguments when you run the class that contains the main() method.

The length of arguments array is not fixed. It becomes equal to the number of arguments that you pass.

The datatype of the parameter in the main() method must be a String array, and its name could be any valid variable name.

Example

class Test
{
	public static void main(String args[])
	{
		System.out.println("The first argument is- "+args[0]);  
	}
}
To compile > javac Test.java  
To run > java Test android

Output

The first argument is- android