Running Example Programs
9. Step 7: Compile the Program
Click in the command window and enter the DIR command.
Step 7: Compile the Program
- Click in the command prompt window.
- Type DIR to check that HelloPlanets.java is there.
- Compile the program: C:\JavaSource> javac HelloPlanets.java
- Run the program: C:\JavaSource> java HelloPlanets
The DIR command lists the files in a DIRectory (also called "folder"). Enter the command (upper or lower case) to see that all the above steps did what you hope. You could also enter the command TYPE HelloPlanets.java to type the text of the file on the screen.
After confirming that the file is there, compile it with the command
Enter a second DIR command to see that the compiler created a bytecode file, HelloPlanets.class
If there are error messages, go back to Notepad and try to correct the errors. Then use "Save" from the "File" menu to save the corrected file. Enter DIR again and check the time to verify that you are saving the file where you expect.
If you copied and pasted the example program, nothing should be wrong. Check that you did not clip off the start or end of the program. Check that you saved the file as "ANSI".
Are we there yet?