next up previous
Next: Matrices Up: Unit 07 Previous: Example: inverting the contents

Parameters passed to a program

By looking at the header of the main method, we can observe that it takes as parameter an array of strings:

public static void main(String[] args)

Such an array contains the strings that are passed as arguments to the program when it is run from command line.

Example: Program that prints out the arguments passed on the command line:

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

Example of usage:

Note that the six strings "here", "are", "some", "command", "line", and "arguments" are the six arguments that are passed to the program when it is executed through the java command.


next up previous
Next: Matrices Up: Unit 07 Previous: Example: inverting the contents