Command Line Arguments in Java

Passing the value at a runtime to main method is called command line argument. Any type of value we can pass in main method array argument.

Command line argument is the argument that passed to a program main method at run time when we run our program.

Which type value we can pass in command line argument?

Any type of value we can pass in main method array argument.

Example of command line argument:


	class Test
	{
		public static void main(String args[])
		{
			int n = args.length;
			for(int i=0; i<n; i++)
			{
				System.out.println("args["+i+"] = "+args[i]);
			}
		}
	}

Output:


	C:\Users\Nature\Desktop\Java>javac Test.java

	//passing a value at runtime to an array in main method.
    
	C:\Users\Nature\Desktop\Java>java Test 1 2 3 4
	args[0]= 1
	args[1]= 2
	args[2]= 3
	args[3]= 4

Post Your Comment