go to previous page   go to home page   go to next page
System.out.println( args[0] );



Command Line Arguments


The words on the command line after the name of the program are the command line arguments. These are familiar to Unix programmers, but less familiar to Windows programmers. They are a convenient way to pass values into a program without a user dialog. There may be any number of command line arguments. The arguments are strings of characters, although some characters like < and > are not allowed. Each argument is separated from its neighbors by spaces.

Not all computer systems support command line arguments. Older Apple computers do not have a command line. Integrated programming environments, such as J++ or Café, typically have limited support for command line arguments.

Here is a sample program:

class StringDemo
  public static void main ( String[] args )
    for (int j=0; j  < args.length; j++ )
      System.out.println( "Parameter " + j + ": " + args[j] );

Say that the user started this program with the command line:

C:/>java StringDemo stringA stringB stringC


What does the program print?