Java ScreenShot
     

Screenshot Core Java 2: Volume I - Fundamentals

Table of Contents
 2.  The Java Programming Environment


Compiling and Running Programs from a Text Editor

An integrated development environment offers many comforts, but there are also some drawbacks. In particular, for simple programs that are not distributed over multiple source files, an environment with its long startup time and many bells and whistles can seem like overkill. Also, many programmers have become accustomed to their favorite text editor and can be reluctant to use the generally wimpy editors that are part of the integrated development environments. Fortunately, many text editors have the ability to launch the Java compiler and interpreter and to capture error messages and program output. In this section, we look at two text editors, Emacs and TextPad, as typical examples.

Java graphics notes_icon.gif

GNU Emacs is available from http://www.gnu.org/software/emacs/. For the Windows port of GNU Emacs, see http://www.gnu.org/software/emacs/windows/ntemacs.html. Be sure to install the JDEE package when using Emacs for Java programming. You can download it from http://jdee.sunsite.dk.

For example, Screenshot-7 shows the Emacs editor compiling a Java program. (Choose JDE -> Compile from the menu to run the compiler.)
Screenshot-7. Compiling a program with Emacs

Java graphics 02fig07.jpg


The error messages show up in the lower half of the screen. When you move the cursor on an error message and press the ENTER key, then the cursor moves to the corresponding source line. Once all errors are fixed, you can run the program by choosing JDE -> Run App from the menu. The output shows up inside an editor window (see Screenshot-8).

Screenshot-8. Running a program from within Emacs

Java graphics 02fig08.jpg


Emacs is a splendid text editor that is freely available for Unix, Linux, Windows, and Mac OS X. However, many Windows programmers find the learning curve rather steep. For those programmers, we can recommend TextPad. Unlike Emacs, TextPad conforms to standard Windows conventions. TextPad is available at http://www.textpad.com. Note that TextPad is shareware. You are expected to pay for it if you use it beyond a trial period. (We have no relationship with the vendor, except as satisfied users of the program.) To compile a program in TextPad, choose Tools -> Compile Java from the menu, or use the CTRL+1 keyboard shortcut.

Java graphics notes_icon.gif

If there is no such menu option, select Configure -> Preferences, then select Tools from the tree on the left. On the right hand side, click the button labeled Add until it drops down and reveals a setting JDK commands. Select that setting, then click Ok. The Java SDK commands are now added to the Tools menu.

Compilation errors are displayed in a separate window (see Screenshot-9).
Screenshot-9. Locating compilation errors in TextPad

Java graphics 02fig09.gif


Move the cursor onto the first line of an error message and press ENTER to move to the matching location in the file. Use the Search -> Jump Next command (or the F4 key) to walk through the remaining error messages. To run a program, select Tools -> Run Java app from the menu, or use the CTRL+2 keyboard shortcut. The program runs in a separate shell window. Screenshot-10 shows a Java program launched from TextPad.

Screenshot-10. Running a Java program from TextPad

Java graphics 02fig10.gif


When the program is completed, you need to press a key to continue and then close the shell window.


Java ScreenShot
     
Top
 

Comments