Compiling and Running Programs from a Text Editor

   

Core Java™ 2: Volume I - Fundamentals
By Cay S. Horstmann, Gary Cornell
Table of Contents
Chapter 2.  The Java Programming Environment


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.

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, Figure 2-7 shows the Emacs editor compiling a Java program. (Choose JDE -> Compile from the menu to run the compiler.)

Figure 2-7. Compiling a program with Emacs

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 Figure 2-8).

Figure 2-8. Running a program from within Emacs

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.

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 Figure 2-9).

Figure 2-9. Locating compilation errors in TextPad

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 Application from the menu, or use the CTRL+2 keyboard shortcut. The program runs in a separate shell window. Figure 2-10 shows a Java program launched from TextPad.

Figure 2-10. Running a Java program from TextPad

graphics/02fig10.gif

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


       
    Top
     



    Core Java 2(c) Volume I - Fundamentals
    Building on Your AIX Investment: Moving Forward with IBM eServer pSeries in an On Demand World (MaxFacts Guidebook series)
    ISBN: 193164408X
    EAN: 2147483647
    Year: 2003
    Pages: 110
    Authors: Jim Hoskins

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net