Steps to work with Java using DOS commands on a Microsoft Windows computer

Basic commands:

  1. start --> run --> cmd
  2. cd to your directory
  3. dir /ad /b list directories
  4. dir /b *.java *.class list the files
  5. javac compile your program
  6. java One run your program


  1. Open a DOS command window
  2. Navigate to the folder containing your Java project
  3. Use notepad to edit your source code file
  4. Use javac command to compile your source code file into a byte code file
  5. Use java command to run your program
  6. Some general hints

Open a DOS command window

  1. Got to the "Start" menu
  2. Select the "Run ..." item
  3. Type "cmd" in the "Open:" field
  4. A DOS window will open, with the current directory as your default directory, something like:
    C:\Documents and Settings\HP_Administrator>


  1. Remember that in DOS and UNIX systems, there is always a space after the command
  2. Use the "cd" command to navigate to the folder (also called the directory) which contains your Java project. For example:
    > cd java
    > cd projectOne
  3. The prompt will tell you the directory you are currently in
  4. Use a version of the "dir" command to get the system to tell you what files are in the current directory
  5. Some helpful options for the "dir" comand:
    1. > dir /ad /b - lists only the directories in a short format
    2. > dir /b - lists the contents of the current directory in a bare format, including files and sub-directories
    3. > dir /b *.java - lists the files ending in java, the java source code file
    4. > dir /b *.java *.class - lists files ending in java or class, the source code and byte code files


  1. Use the command "notepad". Change the word One to whatever you want to call your file. Be sure to follow the Java naming conventions by starting the file name with a capital letter.
  2. If this is a new file, you will be asked if you want to create a new file. Naturally, you should say "yes", which you can do by typing a "y" or by selecting the "yes" button. Since the default is "yes", you may even just hit the "return" key.
  3. If this is an old file, notepad will simply start.
  4. Edit your source code file.
  5. Save your changes using "control + s"
  6. When you are all done, exit using "alt + F" then "x", or "alt + F4"


  1. The simplest command is "javac *.java". This will compile all the Java source code files in this directory, which for modest sized projects is the best choice.


  1. Use the "java" command to run your byte code file, adding the file name after the "java" command. Be sure to capitalize correctly.
  2. Remember that the name of the source code file must match exactly the name of the one public class in the file.
  3. For example, if the source code file is called "", then the byte code file will be called "MyFirstClass.class", and to run the file, you would type:
    > java MyFirstClass


  1. Use the up and down arrow keys to recall previous DOS commands
  2. Use "alt + tab" to move between the notepad window and the DOS command window