Command Line Arguments

Command line arguments are arguments that can be given to a program when it is run (on the command line or in Eclipse's Run Dialogue).

The command line arguments are entered on the command line as a space-separated list.

In the following image, Jane and Doe are command line arguments.

The main method takes in one argument: a String array named args[]. This array will contain any command line arguments that are passed in when we run the program. In this example, args[0] will contain "Jane". Note that in Java, unlike C, the command itself is not stored in args[].

In Eclipse, command line arguments can be passed to the program using the Run Dialogue. Go to Run -> Run Configurations... Highlight the Java Application field and click on the "New launch configuration" icon in the upper left corner. Click on the "Arguments" tab, and your command line arguments can be entered in the "Program Arguments" box.

  1. Create a new class named Lab2_CLA.
  2. Make it read the first name, last name and social security number from the command line.
  3. Give it the same functionality as the Lab2 class.
  4. Run the program from the command line.
  5. Run the program from Eclipse