Command line arguments are parameters that are supplied to the application program at the time of invoking its execution.
They must be supplied at the time of its execution following the file name. In the main () method, the args is confirmed as an array of string known as string objects.
Any argument provided in the command line at the time of program execution, are accepted to the array args as its elements.
Using index or subscripted entry can access the individual elements of an array. The number of element in the array args can be getting with the length parameter.
Example of command line argument
package BestJavaTutorial;
class Addition
{
public static void main(String args[])
{
int a= Integer.parseInt(args[0]);
int b= Integer.parseInt(args[1]);
int ans=a+b;
System.out.println("Sum of a and b is : "+ans);
}
}
Output
Tags:
Core Java