Compiling and Running Programs from a Text Editor

   


An integrated development environment accords many comforts but also insinuates 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. Fortunately, many text editors can launch the Java compiler, launch Java programs, and capture error messages and program output. In this section, we look at Emacs as a typical example.

NOTE

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 (Java Development Environnment for Emacs) when using Emacs for Java programming. You can download it from http://jdee.sunsite.dk. You need JDEE 2.4.3beta1 or later with JDK 5.0.


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.)

Another popular choice is JEdit, a very nice editor written in Java, freely available from http://jedit.org. Whether you use Emacs, TextPad, JEdit, or another editor, the concepts are the same. When you are done editing the source code, you invoke a command to compile the code. The editor launches the compiler and captures the error messages. You fix the errors, compile again, and invoke another command to run your program.

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


The error messages show up in the lower half of the window. When you move the cursor on an error message and press the ENTER key, 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



       
    top



    Core Java 2 Volume I - Fundamentals
    Core Java(TM) 2, Volume I--Fundamentals (7th Edition) (Core Series) (Core Series)
    ISBN: 0131482025
    EAN: 2147483647
    Year: 2003
    Pages: 132

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