When we create a main class in Java, it always has a main method which startups when an application begins. The syntax of main method looks like following:

 public static void main(String[] args) 

It has the keyword “public” “static” and “void”. Public means that the method can be called from anywhere, Static means that we don’t have to create an instance of the class and void mean we are not returning anything. Another part of the main method is “String[] args”, this is the value that passed in by Java Virtual Machine as the application starts. The argument passed is an array and command line argument. To pass the argument from command line following syntax should be followed. “java ProgramName arg1 arg2”. In the above example, I have passed two arguments but we can pass n number of arguments as we have passed an array in the argument.

public class HelloWorld {
      public static void main(String[] args) {
            System.out.println("The number of arguments passed" + args.length);
}
}

The above program will show the number of arguments passed by the user. “args.length” is numeric and if we add that value to the string it will be converted to string. That process is called string concatenation. We can also print the arguments using any of the loops for example we will use for loop and see how it works:

public class HelloWorld {
     public static void main(String[] args) {
           System.out.println("The number of arguments passed" + args.length);
   
           for(int i=0; i< args.lenght; i++){
                 System.out.println(args[i]);
               }
     }
}

The above program will print arguments input by the user in each line.