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.
- 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
- cd to the directory your Java program is in. In order to use
the jdk, set the path as indicated in the next link.
- To compile a java program called Prog1.java, type
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)
String s1 = x;
String s2 = x;
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 and "rocks" will be assigned to x.