Running Example Programs

This chapter provides step-by-step instructions of writing a Java program using a text editor, and then compiling and running this program from command prompt. Several Integrated Development Environments (IDEs) are mentioned in this chapter. We have already installed NetBeans. That and Eclipse are the most popular in Java professional practice.

9. Step 7: Compile the Program


Click in the command window and enter the DIR command.

Step 7: Compile the Program

RUN: Compile and Run the program:
  1. Click in the command prompt window.
  2. Type DIR to check that is there.
  3. Compile the program: C:\JavaSource> javac
  4. 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 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".

Question 10:

Are we there yet?