Running Java Programs from DOS
Our First Program.
public class Welcome {
public static void main( String [] args ) {
System.out.println("Welcome to CSC211");
System.out.print("Good ");
System.out.print("Luck and ....\n");
System.out.println("Have a great quarter");
} // end main
}// end Welcome class
Getting the program to run.
- Install Java 2 SDK version 1.4.   Get it here
(If you already have java installed skip this)
Make sure you click on the column that is titled SDK.
- Create a directory(folder) on your C drive named csc211.
- Using an editor (notepad or TextPad) enter in the source code.
- Save as Welcome.java in directory csc211
- When saving a java class, the file name must always be the same as the public class.
- Go to the command prompt:
- Click the start button
- Select run
- Enter cmd or command (depending on your OS) in the combo box labeled open.
- Navigate to the directory csc211.
- Some DOS commands
cd .. takes you back one directory.
cd \ takes you to the root.
cd csc211 changes to directory csc211
dir /p displays the names of sub directories / files in the current directory.
- Once you are in directory csc211 type:
javac Welcome.java
javac is the name of the compiler. If all goes well, you should see
a file named Welcome.class ( type dir /p
). This is called the bytecode file.
If this does not compile, check your syntax. If the syntax is ok and you see a message similar to
bad command or javac is not recognized
You will have to set your path variable.
- If you do not know how to set your path follow
this link
read section 4
- To run, send the bytecode file to the java interpreter. At the command prompt enter..
java Welcome