A Useful Java Programming Environment


Working on Java Programs

When you are working on a program in any object-oriented language, you are typically working with several files, each containing code for a class. You do not write all of the code at once, compile it, run it, and expect to be done. Instead, you add a little bit of functionality at a time. For each increment of functionality, you usually need to modify several of the class files, compile them, then run the modified program to check the correctness of the new functionality. Even if you are an experienced programmer, you should expect to make some mistakes, so you may need to go back and modify some of the files, recompile them, and rerun the program. For this kind of work, it is important to have program development tools set up to simplify the editing, compilation, and program execution.

For CS 2121, I strongly urge you to use the emacs editor for creating and modifying program files. It is set up so that it runs in its own window, independent of other development software that you are using.

For most of the programs that you will write, you will be creating Java applets. The most convenient tool for executing applets is the appletviewer program. Again, it runs in its own window.

Finally, you will be writing programs on a UNIX machine, so you need terminal window for giving UNIX commands. This is the window that is used to compile your programs using the javac compiler. When you are working from a Windows machine, such as the machines in the MWAH 177 lab, this is the first window that you open up with X-Win32. On UMD Windows machines, you can start up an X-Win32 terminal to our "ub" machine by doing the following.

On UNIX machines, such as the ones in the Computer Science Lab (HH 314), you can open up a terminal window directly.

Most of the time you have three windows for doing your work.

The use of these three windows is described in more detail in the following sections. In addition, you may also have a browser window open for reading instructions for a lab exercise or programming assignment.

It is helpful to set up separate directories for each of the exercises and assignments that you work on. The sections below assume that you are doing this.

The Terminal Window

This window is used for all UNIX commands. The commands that you use depend on how far along you are in developing your program.

When you are first starting an exercise or assignment,

When you are starting a new work session after the first, you will normally use the same commands except for the mkdir command. You only need to create the directory the first time.

After you have done some editing and are ready to compile your program,

When you are ready to run your program for the first time in a work session,

For further work in a work session, if you use emacs and appletviewer as described in the following sections then you will only need to give their commands once in a work session. Then further work involves cycles of editing in the emacs window, giving the javac command in the terminal window to compile, and reloading the program in the appletviewer window.

Here are some more UNIX file commands that you may use from time to time.

Here are some UNIX directory commands that you may occasionally use.

UNIX maintains a list of the 20 most recent commands. You can re-execute an earlier command with just an exclamation point (!) followed imediately by enough of the command to distinguish it from other commands. If you earlier recompiled everything with

    javac *.java
Then you can do it again with
    !j

The emacs Window

If you have started up the emacs program with "emacs &" then you will not need to shut it down to compile or start the appletviewer program. You can just keep the emacs window open for the duration of a work session. Each time you open a file with the "Open File" menu item on the "Files" menu, it will be added to the emacs buffer list. You can then re-edit it by selecting it from the "Buffers" menu. Be sure to save your work on one file before recompiling or moving on to another file. This is done with the "Save Buffer" menu item on the "Files" menu.

The appletviewer Window

If you have started up the appletviewer program with "appletviewer &" then you will not need to shut it down to do other work. After you have modified your program and recompiled it, you can have appletviewer reload the revised program by selecting "Reload" from the "Applet" menu.

Be sure that you have saved files and recompiled them before reloading the program. If you have made changes in a program but do not get any expected changes in its behavior in appletviewer, it may be due to failure to save the buffer or recompile. Even if you think that you saved changes and recompiled, do it again to make sure.