Java-Command Line Arguments

Command Line Arguments

The main() method also takes an argument. This is achieved by passing command line arguments is the information that directly follows the programs name on the command line when it is executed. To access the command line arguments inside a java program is very easy. They are stored in String array passed to main(). The following program display all the command line arguments.

Program

Program Source

public class Javaapp {
  
    public static void main(String[] args) {
        
        if(args.length!=0)
        {
            System.out.println("Arguments[0] : "+args[0]);
            System.out.println("Arguments[1] : "+args[1]);
            System.out.println("Arguments[2] : "+args[2]);
        }else
            System.out.println("Arguments not found");
    }
}

Leave a Comment