Using the Command Line Arguements

Command Line Arguements
Sometimes, there might arise a need for a program to run it in accordance with the specific input provided at the time of running the program. Command line arguements serve this purpose in java by allowing the user to input some values at the time of running the java program.
As the name implies, this feature is for only the programs which run on/from the command line interface. The input provided at the command line along with the instruction of running the java application, is stored in a String array and can be used in the program to make changes in the way program will behave.
Syntax:
They are directly passed to the main() of the java program.
public static void main(String args[])
the args[] is an array of strings, and it is called as command line arguements because the value of args[] can only be given at the run time from the command line. But wonder how to use it in your program?
This is simple, take a loot at the demo code that makes use of the command line arguements.



//Demo Code for using the Command Line Arguements in your program


class CommandLineArgs
{

public static void  main(String args[])
{
int sum = 0;
for(int i=0;i<args.length;i++)
{
sum = sum + Integer.parseInt(args[i]);
}
System.out.println("Sum is "+sum);
}
}

You might want to read or download the chapter wise Java SE tutorials.