What is command line argument in java

 What is command line argument in java :-

            Command line argument is a technique by which programmer input the command line at the time of execution of java program.
 Example :-
                   D:\core java\c1>java<class name>11.

In the  above example 11 is command line argument.

  • What ever the command line argument we pass they are always store in an array of string type which is implicitly constructed by JVM.

What is command line argument in java

Is it mandatory that the main method argument must be array reference of string type :-

  • yes, the main method argument must be array reference of string type. As we know what ever  the command line argument we pass there always store in an array of string type. which is implicitly constructed by JVM. 

            JVM assign the base address of the array to the main method argument so the main method argument must be array reference of string type.

When we run a java program without command line argument is it mandatory that we pass method argument :-

  • when we run a java program without a command line argument then also JVM construct an array of string type, where the size of the array is zero.

Program :-

public class argument
{
public static void main(String args[])
{
int size=args.length;
System.out.println("Size of the array is "+size);
}
}

Output :-

What is command line argument in java

Program :-

public class argument1
{
public static void main(String args[])
{
int x=0;
while(x<args.length)
{
System.out.println(args[x]);
x++;
}
}

}Output :-

What is command line argument in java
What is command line argument in java.
for more detail follow my Instagram id - https://www.instagram.com/asitmaharana10/

Thank you.