Specifying Run Arguments in jGrasp

A Java class that can serve as an application program (meaning that you can "run" it) must have a main() method. When the application is run, execution begins in that method, the heading of which must be as follows:

public static void main(String[] args)

Well, you can change args to any legal identifier, but otherwise the heading must look like this.

What this heading indicates is that main() receives as a parameter an array of String objects. But how does one, when running a program, "pass" a parameter to it?

In the context of the IDE jGrasp, you would do this:

  1. Make the application program to be run the current class (by clicking on the window containing its source code).
  2. Click on Build (in the Menu Bar) so that the associated menu appears.
  3. Click on the Run Arguments box on the menu so that it has a checkmark in it. (Recall that "parameter" and "argument" are somewhat synonymous.) A text box should immediately appear above the application program's source code.
  4. Enter into that text box one or more arguments, separated by spaces. Typically, such an argument might be the name of a file that you intend for the program to use as input. If that file were named data.txt, you would enter that into the text box (with no quotes).
  5. Click on the Run icon.