Using the Command Line on the PC

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 below.
  5. To compile a java program called, type javac 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)
         if(x.length > 0)
              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].

Adding the JDK to Your Path

  1. In Windows Explorer, right-click My Computer.
  2. Select Properties.
  3. Click the Advanced tab.
  4. Click the Environment Variables button.
  5. Select Path in the System Variables window
  6. Click Edit.
  7. Type C:\Program Files\java\jdk1.6.0_01\bin or whichever version of jdk you are using, at the end of the path list and click OK several times.