Steps to work with Java using DOS commands on a Microsoft
- start --> run --> cmd
- cd to your directory
- dir /ad /b list directories
- dir /b *.java *.class list the files
- javac One.java compile your program
- java One run your program
- Open a DOS command window
- Navigate to the folder containing your
- Use notepad to edit your source code file
- Use javac command to compile your source
code file into a byte code file
- Use java command to run your program
- Some general hints
Open a DOS command
- Got to the "Start" menu
- Select the "Run ..." item
- Type "cmd" in the "Open:" field
- A DOS window will open, with the current directory as your
default directory, something like:
C:\Documents and Settings\HP_Administrator>
- Remember that in DOS and UNIX systems, there is always a
space after the command
- Use the "cd" command to navigate to the folder (also called
the directory) which contains your Java project. For example:
> cd java
> cd projectOne
- The prompt will tell you the directory you are currently in
- Use a version of the "dir" command to get the system to tell
you what files are in the current directory
- Some helpful options for the "dir" comand:
- > dir /ad /b - lists only the directories in a short
- > dir /b - lists the contents of the current directory
in a bare format, including files and sub-directories
- > dir /b *.java - lists the files ending in java, the
java source code file
- > dir /b *.java *.class - lists files ending in java or
class, the source code and byte code files
- Use the command "notepad One.java". 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.
- 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.
- If this is an old file, notepad will simply start.
- Edit your source code file.
- Save your changes using "control + s"
- When you are all done, exit using "alt + F" then "x", or "alt
- 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.
- Use the "java" command to run your byte code file, adding the
file name after the "java" command. Be sure to capitalize correctly.
- Remember that the name of the source code file must match
exactly the name of the one public class in the file.
- For example, if the source code file is called
"MyFirstClass.java", then the byte code file will be called
"MyFirstClass.class", and to run the file, you would type:
> java MyFirstClass
- Use the up and down arrow keys to recall previous DOS commands
- Use "alt + tab" to move between the notepad window and the
DOS command window