So you've written a .java file, now what?

This is part of a series where I am posting a few of my common threads from the Introduction to Programming (Java) course that I'm teaching.

After writing a .java file, there are a few steps that must take place in order for you to run your code. Let's use the file "" for the following example.

Step 1: Locate your .java file. Where did you save the file? Let's pretend that the file exists here "c:/JavaPrograms/"

Step 2: Open up your command prompt. A shortcut is to press "control-R" and type "cmd". (Windows users only)

Step 3: Change Directory to the .java file. In the command prompt you can type "cd c:/JavaPrograms/"

Step 4: Compile the Java file. In the command prompt you can type "javac"

Step 5: Fix and Errors. If step 4 produces and errors, you must fix them. To fix an error, you must open up the .java file in an editor and make sure that the code is correct. Typical errors are missing symbols and typos. After you ATTEMPT to fix the errors, you must re-compile again until all of the errors are gone.

Step 6: Run the program. If there were no compile errors, a .class file will be generated. It may look like "c:/JavaPrograms/MyProgram.class" and exist in the same directory. To run the file, you can type the following on your command prompt "java MyProgram"