Description

Command line arguments


When we run a program, the arguments that we give along with the program name in the linux console (or in eclipse using open run dialogue) are called command line arguments.

java Lab9 hello world

The arguments that we pass in the command line are available to the program as parameters passed to main. When we enter them in the command line, we enter them as a space-separated list.

public class Lab09
{

	public static void main (String [] args)
	{
		//your code goes in here
	}
}

We see that main method take 1 parameter as its input ie the String array args[]
args[] is an array of strings which contains the actual command line arguments. Therefore for a command line argument in Linux,

java Lab9 hello world

args[0] will contain "hello"
args[1] will contain "world"