Any number of arguments can be passed to the java program through command line. While running the program any things written after the name of the class are the command line arguments. Arguments are delimited by the space.

This sample code prints all the command line arguments to the console.

 public class CmdLnArgmntExp {

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

}

Run the program as the follows.

Java CmdLnArgmntExp arg1 arg2 arg3 arg4

Output:

arg1
arg2
arg3
arg4