Using the Command Line

Samuel Marateck 2006

You get the command line by going to the Start menu and selecting run. When the run window appears, type cmd.

  1. On my computer, I see C:\Documents and Settings\sam>.
  2. Type dir (it stands for directory) and one of the directories shown will be My Documents.
  3. Type cd My Documents and the directory chosen will be My Documents
  4. cd to the directory your Java program is in. In order to use the jdk, set the path as indicated in the next link.
  5. To compile a java program called Prog1.java, type javac Prog1.java on the command line.
  6. If your program compiles, type java Prog1 at the command line.

Here's a program that enables you to enter data at the command line.

public class Prog1
{
    public static void main(String[] x)
    {
         String s1 = x[0];
          String s2 = x[1];
         System.out.println(s1 + s2);
    }
}

When you run the program, type the following at the command line:
java Prog1 nyu rocks.

"nyu" will be assigned to x[0] and "rocks" will be assigned to x[1].