Using Command-Line Arguments with main method

A command-line argument is the information that follows the program's name on the command line.

The command-line arguments are stored as string array passed to main().
For example, the following program displays all of the command-line arguments:
  

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

  

Try executing this program, as shown here:


java Main this is a test 100

When you do, you will see the following output:


args[0]: this 
args[1]: is 
args[2]: a 
args[3]: test 
args[4]: 100
Home 
  Java Book 
    Class  

Methods:
  1. Syntax for Method Creation
  2. Recursion
  3. Method with Parameters
  4. Pass-by-value vs Pass-by-reference
  5. What is Methods Overloading
  6. The main() Method
  7. Using Command-Line Arguments with main method
  8. Subclasses and Method Privacy