Command line arguments

class PrintArgs {

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

The name of the class is not included in the argument list.

Command line arguments are passed in an array of Strings. The first array component is the zeroth.

For example, consider this invocation:

$ java printArgs Hello There

args[0] is the string "Hello". args[1] is the string "There". args.length is 2.

All command line arguments are passed as String values, never as numbers. Later you'll learn how to convert Strings to numbers.


Previous | Next | Top | Cafe au Lait

Copyright 1997-2006 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified September 2, 1997