Compiling, Running, and Testing with an IDE

Problem

Several tools are too many.

Solution

Use an integrated development environment.

Discussion

Many programmers find that using a handful of separate tools -- a text editor, a compiler, and a runner program, not to mention a debugger (see Section 1.13) -- is too many. An integrated development environment (IDE[6]) integrates all of these into a single toolset with a (hopefully consistent) graphical user interface. There are many IDEs to choose from, ranging from text editors that allow you to compile and run a Java program, all the way up to fully integrated tools with their own compilers and virtual machines. Class browsers and other features of IDEs round out the purported ease-of-use feature-sets of these tools. It has been argued many times whether an IDE really makes you more productive or if you just have more fun doing the same thing. However, even the JDK maintainers at Sun admit (perhaps for the benefit of their advertisers) that an IDE is often more productive, although it hides many implementation details and tends to generate code that locks you into a particular IDE. Sun’s Java Jumpstart CD (part of Developer Essentials) said, at one time:

The JDK software comes with a minimal set of tools. Serious developers are advised to use a professional Integrated Development Environment with JDK 1.2 software. Click on one of the images below to visit external sites and learn more.

This is followed by some (presumably paid) advertising links to Inprise/Borland JBuilder, WebGain Visual Cafe, and Sybase PowerJ development suites.

I don’t plan to debate the IDE versus the command-line process; I’m just going to show a few examples of using a couple of the Java-based IDEs. One that runs on both MS-Windows and Unix platforms is Forte, which is a free download from Sun. Originally created by NetBeans.com, this IDE was so good that Sun bought the company, and now distributes the IDE for free. Forte is also open sourced. You can download the compiled version from http://www.sun.com/forte/ffj/ and the open source version from http://www.netbeans.org.

Forte comes with a variety of templates. In Figure 1-6, I almost selected the MDI (multiple-document interface) template, but instead opted for the Swing JFrame template.

Forte: “New From Template” dialog

Figure 1-6. Forte: “New From Template” dialog

Then in Figure 1-7, Forte lets me specify a class name and package name for the new program I am building.

Forte: name that class

Figure 1-7. Forte: name that class

In Figure 1-8, I am building the GUI using Forte’s GUI builder. Select a visual component in the upper right, and click on the form where you want it. While there are several things about Forte that most people (including myself) find quirky, I do like the fact that it defaults to using a BorderLayout ; some other IDEs default to using no layout at all, and the resulting GUIs do not resize gracefully.

Forte: GUI building

Figure 1-8. Forte: GUI building

I also like the way Forte handles GUI action handlers (see Section 13.5). You simply double-click on the GUI control you want to handle actions for, and Forte creates an action handler for it and puts you into the editor to type the code for the action handler. In this case I made a deliberate typing error to show the effects; when I click the Build Project menu item, the offending line of code is highlighted in bright red, both in the source code and in the error listing from the compiler (see Figure 1-9).

Forte: compilation error highlighted

Figure 1-9. Forte: compilation error highlighted

Some people don’t like the user interface of Forte. There are many popular IDEs for Java, especially on the MS-Windows platform, and almost everybody who uses one has a favorite, such as Borland JBuilder, WebGain Visual Cafe, or IBM Visual Age for Java. Most of them have a free version and a Pro version. For up-to-date comparisons, you may want to consult the glossy magazines, since IDEs are updated relatively often.

On MacOS X, the bundled Developer Tools includes a reasonably good IDE, shown in Figure 1-10. MetroWerks CodeWarrior and other IDEs are also available for MacOS X.

MacOS X Developer Tools IDE: main windows

Figure 1-10. MacOS X Developer Tools IDE: main windows

Figure 1-11 shows the MacOS X bundled IDE running a trivial application built using its default frame-based template.

MacOS X Developer Tools IDE: application built and running

Figure 1-11. MacOS X Developer Tools IDE: application built and running

What about the speed of IDEs? One way to categorize an IDE is by whether it was written to be as portable as Java or to run well on only one platform. Forte, JBuilder, and others are written in Java and can, in theory, be run on any platform that has Java 2 support. Visual Cafe, IBM Visual Age for Java, MetroWerks CodeWarrior, and others are built out of existing frameworks and provided as compiled binaries; these have major components that depend on one or another platform and cannot be “run anywhere.” The native code IDEs tend to be a bit faster, although the difference is diminishing as Java runtimes get better and as computers get faster. When was the last time you bought a new computer system with a Pentium 133 processor?



[6] It takes too long to say, or type, Integrated Development Environment, so I’ll use the term IDE from here on. I know you’re good at remembering acronyms, especially TLAs.

Get Java Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.