Recipe 1.3 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 Recipe 1.13) is too many. An integrated development environment (IDE[2]) incorporates all of these into a single toolset with a (hopefully consistent) graphical user interface. Many IDEs are available, ranging 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:

[2] 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.

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 various commercial development suites. I do find that IDEs with "incremental compiling" features which note and report compilation errors as you type, instead of waiting until you are finished typing do provide somewhat increased productivity for most programmers. Beyond that, I don't plan to debate the IDE versus the command-line process; I use both modes at different times and on different projects. I'm just going to show a few examples of using a couple of the Java-based IDEs.

One IDE that runs on both Windows and Unix platforms is NetBeans, which is a free download. Originally created by NetBeans.com, this IDE was so good that Sun bought the company and now distributes the IDE in two versions that share a lot of code: NetBeans (formerly called Forte, distributed as open source), and Sun One Studio (commercial, not open sourced). There is a plug-in API; some .nbm files will work either on the free or the Studio version while others work only on one or the other. You can download the free version and extension modules from http://www.netbeans.org; the commercial version can be had from http://www.sun.com/.

NetBeans comes with a variety of templates. In Figure 1-1, I have opted for the Swing JFrame template.

Figure 1-1. NetBeans: New From Template dialog
figs/jcb2_0101.gif


In Figure 1-2, NetBeans lets me specify a class name and package name for the new program I am building.

Figure 1-2. NetBeans: Name that class
figs/jcb2_0102.gif


In Figure 1-3, I am building the GUI using NetBeans' 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 NetBeans that most people 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.

Figure 1-3. NetBeans: GUI building
figs/jcb2_0103.gif


I also like the way NetBeans handles GUI action handlers (see Recipe Recipe 14.4). You simply double-click on the GUI control you want to handle actions for, and NetBeans 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-4).

Figure 1-4. NetBeans: Compilation error highlighted
figs/jcb2_0104.gif


Another popular cross-platform, open source IDE for Java is Eclipse, originally from IBM. Just as NetBeans is the basis of Sun Studio, so Eclipse is the basis of IBM's WebSphere Studio Application Developer.[3] Eclipse tends to have more options than NetBeans; see for example, its New Java Class wizard shown in Figure 1-5. It also features a number of refactoring capabilities, shown in Figure 1-6.

[3] WebSphere Studio Application Developer describes itself, in its online help, as "IBM's implementation of Eclipse" and gives a link to http://www.eclipse.org/.

Figure 1-5. Eclipse: New Java Class
figs/jcb2_0105.gif


Figure 1-6. Eclipse: Refactoring
figs/jcb2_0106.gif


Of these two major open source IDEs, many people like NetBeans and many like Eclipse. Many other IDEs are available for Java, especially on Windows, and almost everybody who uses one has a favorite, such as Borland JBuilder, WebGain Visual Cafe, Sun Studio, or IBM WebSphere Studio Application Developer. Most of them have a free version and/or a trial version as well as a Pro version. For up-to-date comparisons, you may want to consult the glossy magazines, since IDEs are updated relatively often.

Mac OS X includes Apple's Developer Tools. The main IDE is Xcode in 10.3 (shown in Figure 1-7). Unlike most IDEs, Apple's IDE does not include a GUI builder; a separate program, called Interface Builder, handles this task. Both tools can be used with a variety of programming languages, including C/C++, Objective C, and Java. While the Interface Builder is one of the nicer GUI builder tools around, at present it builds only Cocoa applications, not Swing applications. Figure 1-8 shows Xcode running a trivial application built using its default frame-based template.

Figure 1-7. Xcode (Mac OS X): Main windows
figs/jcb2_0107.gif


Figure 1-8. Xcode IDE (Mac OS X): Application built and running
figs/jcb2_0108.gif


How do you choose an IDE? Given that all the major IDEs can be downloaded free (Eclipse, NetBeans), "free" but without source, or at least in free trial versions, you should try a few and see which one best fits the kind of development you do. Regardless of what platform you use to develop Java, if you have a Java runtime, you should have plenty of IDEs from which to choose.

See Also

For NetBeans, see NetBeans: The Definitive Guide by Tim Boudreau, Jesse Glick, Simeon Greene, Vaughn Spurlin, and Jack J. Woehret (O'Reilly). For Eclipse, see Eclipse Cookbook by Steve Holzner (O'Reilly) or The Java Developer's Guide to Eclipse by Sherry Shavor, Jim D'Anjou, Scott Fairbrother, Dan Kehn, John Kellerman, and Pat McCarthy (Addison Wesley). Both IDEs are extensible; if you're interested in extending Eclipse, the book Contributing to Eclipse: Principles, Patterns, and Plugins (Addison Wesley) was written by noted OO theorists Erich Gamma (lead author of Design Patterns) and Kent Beck (author of Extreme Programming Explained).



Java Cookbook
Java Cookbook, Second Edition
ISBN: 0596007019
EAN: 2147483647
Year: 2003
Pages: 409
Authors: Ian F Darwin

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