Windows Command Prompt in 15 Minutes

There are only a few Command Prompt commands that you will need to master to make it through COS 126. The following is a brief tutorial covering the most important ones.

What is Command Prompt?

The Command Prompt program allows you to work in an environment that looks more like a traditional operating system as opposed to the icon based Windows environment. In Command Prompt, you will use your keyboard. You won't use your mouse at all. Command Prompt works at a lower level than Windows. This means that you will have more control over the machine. The disadvantage is that it is less user-friendly.

You will need the command prompt in COS 126 to compile and execute your Java programs. Learning the Command Prompt also provides a gradual transition to Unix and Linux systems, which are prevalent in science, engineering, and industry.

To launch Command Prompt select Start -> Run and type cmd in the box.

The Command Prompt shows up as a black terminal window. The command prompt should look something like:


This is where you type commands. The boldface type below (that follows the command prompt) is what you should type as you work through this tutorial. Windows does not care if you use upper or lower case. That means that command cd is the same as CD. It also means that, in Windows, file is the same as This is NOT true in the system to which you will be submitting your files. Be very careful!!!

Some Useful Commands

Working with Files and Directories

You can also use Command Prompt commands to organize files into a directory hierarchy. These commands are equivalent to corresponding commands that you access via the Windows point-and-click interface. It is useful to be familiar with both interfaces for managing files.


Two important abstractions in Command Prompt are standard input and standard output. By default standard input is your keyboard, and standard output is your computer screen. For example, in Assignment 1, we write a program that reads input using and writes output using System.out.println(). To run our program, the user types the command "java CenterofMass" and enters double type values in triplets: xposition yposition mass from the keyboard. The results appear in the terminal window.

C:\introcs\loops> java CenterofMass
0 0 10
1 1 10
0.5  0.5  20


Another useful abstraction is piping.  Piping is when the output of one program is used as the input of another program. For example, suppose we want to view the output of a program, but there is so much that it whizzes by on the screen too fast to read. (The program prints out a bunch of random integers.) One possible way to accomplish this is to type the following two commands.

C:\introcs> java RandInts > temp.txt
C:\introcs> more < temp.txt
Note that more will work by redirecting the file temp.txt to standard input (as is done here) or by simply using the filename (as is done at the beginning of the document). Instead, we could do this in one line using the pipe symbol '|'
C:\introcs> java RandInts | more

This is often useful when debugging a program, especially if your program goes into an infinite loop and you want to see the first few values that it prints.

Written by Jake Brenner, Donna Gabai and Kevin Wayne.