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.
- On my computer, I see C:\Documents and Settings\sam>.
- Type dir (it stands for directory) and one of the directories
shown will be My Documents.
- Type cd My Documents and the directory chosen will be My
Documents
- cd to the directory your Java program is in. In order to use
the jdk, set the path as indicated below.
- To compile a java program called Prog1.java, type
javac Prog1.java
on the command line.
- 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
- In Windows Explorer, right-click My Computer.
- Select Properties.
- Click the Advanced tab.
- Click the Environment Variables button.
- Select Path in the System Variables window
- Click Edit.
- 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.