Running Java Programs


Java development software

To code and test Java programs, you need Java development software. Many products exist, but you don't need anything elaborate or costly. In fact, the more sophisticated packages can distract you from learning Java as you get wrapped up in all their fancy features.

To write and edit Java code, all you need is a text editor like the Notepad accessory in Microsoft Windows. To compile and execute what you have written, all you need is the free J2SE SDK (Java 2 Standard Edition Software Development Kit) from Sun Microsystems. With these simple tools, the most complex Java programs and applets can be developed.

To obtain the required software:


Creating a Test project

To simplify coding and testing, you need a "Test Project". This is a disk folder containing four source files. One file will be continuously modified to hold the code you want to test. The other three files will not be modified but are needed to support the code you are testing. The files are as follows:

File Name


Source statements of the main application class (the code you want to test)


Source statements of a web page to launch the main application class if it is an applet

Source statements of a class that supports keyboard data entry. It is provided as a convenience for non-graphical programs. For information on how to use this class, see the documentation for my Keyboard class.

Source statements of a class having many useful methods that may be used by the application. For information on how to use these methods, see the documentation for my Utility class.

Creating your Test project is a simple, one-time activity as follows:


  1. Create a folder named Test on your computer.

  2. Open or download this Test project as a zipped archive.

  3. Copy the four files from the zipped archive to your Test folder.


Preparing to run the Test project

Coding and testing is a three-step process that involves two windows. Your text editor (Notepad) is run in one window and used to edit Java source statements. A Command Prompt (MS-DOS) window is needed to compile and execute the resulting source file. The two windows and their functions are summarized by this diagram:

Text Editor (Notepad) Window

Command Prompt (MS-DOS) Window


1.  Edit source statements




2.  Compile source statements into bytecode

3.  Execute bytecode


Prepare for testing by opening these two windows. In a College of Business lab where drive D: is your zip drive, follow these steps:

  1. Start a Notepad window. To do this,

  1. Open the Run dialog box by clicking the Start button and selecting Run...

  2. In the Run dialog box, type notepad and press ENTER.

  1. Start a Command Prompt (MS-DOS) window and make it reference your Test project. To do this,
  1. Open the Run dialog box by clicking the Start button and selecting Run...

  2. In the Run dialog box, type cmd and press ENTER.

  3. Within the Command Prompt window, enter the following three MS-DOS commands:

cd Test
set classpath=

These commands change the default drive and directory to that of your Test project and reset the system's classpath so that class files generated by the compiler will be found at run time.

The command prompt should now be:   D:\Test>


Running the Test project

Using your Test project and the two windows described above, you can edit, compile, and execute any program or applet as follows:

  1. Use the text editor (Notepad) window to view, modify, and save the contents of ONLY the "" file within the Test project:

Text Editor (Notepad)


Source Files (in Test project)

Code to be tested




NOTE: Many small sample programs are embedded in these Web pages. To run an embedded sample, "copy" it from its Web page, "paste" it into your text editor window, and save the file under the name "" in your Test project. You are then ready to compile and execute as described below.

  1. Compile the "" source file by entering the following command in the Command Prompt window:


If no errors are detected, the command prompt will re-appear in a few seconds and the compiler will have automatically created a file named "App.class" within your Test project. This file will contain the bytecode of the program to be tested.

If an error is occurs, the compiler displays a message with the line number of the bad source statement. To see and fix the statement, switch to your text editor window. In Notepad, the Edit | Go to... menu choice lets you jump to a specified line number within the source file.

  1. Execute the generated bytecode file using a single command in the Command Prompt window as follows:

Through practice, you will quickly become familiar with these three steps as you continuously edit, compile, and execute Java code.