Dr. Dobb's is part of the Informa Tech Division of Informa PLC

This site is operated by a business or businesses owned by Informa PLC and all copyright resides with them. Informa PLC's registered office is 5 Howick Place, London SW1P 1WG. Registered in England and Wales. Number 8860726.


Channels ▼
RSS

NetBeans 4.1 & Eclipse 3.1


August, 2005: NetBeans 4.1 & Eclipse 3.1

Eric is a consultant in New York and has worked extensively in Java and C++ developing real-time trading and financial applications. He can be contacted at [email protected].


When I began my career as a software developer, the modern concept of an integrated development environment (IDE) was yet to be defined. Instead, developers would simply use their favorite editor and compile code from the command line. I remember how much I looked forward to getting a cup of coffee as I started the compiler, knowing how long it would take. When the compiler was finished, I would go through any errors that were listed, open the appropriate source module, and locate the offending line of code. This was a luxury, veteran developers told me, compared to punch cards or submitting code to be compiled as overnight batch jobs.

Everything changed with Microsoft's Visual C++ 1.0. There were other IDEs available for Windows development (Borland and Symantec both offered them), but Visual C++ quickly took the lead. Over time, Microsoft set the standard for modern IDE features with Visual Studio, which included tools for building C, C++, and Visual Basic applications for Windows. With Visual J++, Microsoft even extended its support to Java. Alas, Visual J++ was abandoned, never to be extended to support Java past Version 1.1. For me, this put Java development back into the "dark ages" of using a plain old editor and command line.

Quickly, vendors such as Borland and Symantec offered Java IDEs, with JBuilder and Visual Café, respectively. However, these IDEs felt clunky because they placed their own abstractions on top of important aspects of Java development, such as setting the classpath and defining packages. Because of this, not to mention a high price tag and the fact that it was still difficult (if not impossible) to debug J2EE applications running inside application servers, many developers stuck with simple editors for development. Debugging often consisted of adding System.out.prinln statements in the code.

Sun recognized the shortcomings of Java development tools and offered its own IDE after acquiring NetBeans Developer from Forte. Today, it's simply called NetBeans, and Sun has made it open source. I first used NetBeans for Java development about two years ago and wasn't entirely comfortable with it. Consequently, I began to use Eclipse. With it, I could develop and debug Java code within a full-featured IDE that didn't feel clunky. Soon, application server vendors such as BEA offered Eclipse plug-ins, letting us debug J2EE applications as well.

NetBeans 4.1 Overview

With the release of NetBeans 4.1 (http://www.netbeans.org/), NetBeans has become a premier Java development platform, letting you easily build, package, and deploy standalone J2SE applications, J2EE applications (EJBs), Java web services, and (its most unique feature) wireless mobile MIDP applications that run on cell phones. NetBeans features include:

  • Support for both J2SE 1.4.2 and 1.5 (development and debugging).
  • Support for both J2EE 1.3 and 1.4 (Servlet and/or EJB development, deployment, and debugging).
  • Support for J2ME Wireless Toolkit 2.2, MIDP 2.0, and CLDC 1.1 (development, debugging, and emulation).
  • The ability to create, test, and consume web services.
  • Project builds that are based entirely on Apache Ant scripts. Your projects can be built outside of NetBeans using the Ant scripts it composes, or you can import your existing Ant scripts into NetBeans.
  • Code refactoring that lets you easily rename fields, methods, classes, interfaces, and packages, as well as add get/set methods for fields.
  • Code profiling that lets you check for memory leaks and CPU performance bottlenecks.
  • Code editing features such as code-specific fonts and colors, code formatting, automatic indent, bookmarks, tasks, code folding (expand and collapse), auto completion, macros, and block tabbing and commenting. Configurable editor settings for Java, JSP, CSS, HTML, XML, DTS, properties, and plain text files.
  • A classpath that can be set per project through a straightforward interface. You can simply add JAR files or folders directly, or you can add libraries, which are sets of one or more JAR files that you group together in advance.
  • A Navigator component (part of the editor UI) that lets you quickly browse through the methods, fields, and inheritance tree for each Java source module without scrolling through the source file itself.

Overall, the NetBeans interface is attractive and efficient (see Figure 1). The default layout is as you would expect, with a component to display your currently opened projects, a portion of the screen dedicated to code editing, the navigator component, and an area to display the output of builds and debug sessions. The project display does a nice job of breaking out the components of each project, such as the source files (by package), the libraries and JAR files used in the project, and any test packages you may want to include to test your code. When you're in debug mode, there are components to display the states of variables, show the entire call stack, and view the application's running threads. The layout is customizable, visually appealing, and wastes no space.

I found the NetBeans UI to be responsive, and in many areas slightly more responsive than Eclipse. In particular, NetBeans performed better while opening/ closing projects, and while stepping through code in the debugger. The performance difference isn't great, but noticeable.

But NetBeans is technically more than just an IDE. It is an entire platform that can be used as an application runtime, eliminating the need for you to write window, menu, or other UI-related code. The NetBeans platform is a framework that can be used to build application user interfaces, with data storage access and presentation management. When you use the full NetBeans development platform, you simply concentrate on your application's business logic.

Eclipse 3.1 and the Web Tools Platform Overview

In many ways, it's difficult to compare Eclipse to NetBeans. The overview documentation for Eclipse (http://www.eclipse.org/) describes the platform as "an open, extensible IDE for anything, and nothing in particular." Eclipse is a platform that can be used for Java development, as well as C, C++, Smalltalk, COBOL, Perl, Python, and Fortran. There are tools that integrate UML and other design methodologies into the platform, too. However, in this article I focus on the Eclipse plug-ins and facilities for developing Java applications.

When you install the appropriate plug-ins, such as those available for WebLogic (https://eclipse-plugin.projects.dev2dev.bea.com/) and Tomcat (http://jakarta.apache.org/tomcat/resources.html), along with the Eclipse Web Tools Platform (http://www.eclipse.org/ webtools/index.html), you can develop, deploy, and debug J2EE applications with Eclipse 3.1. Among Eclipse's features are:

  • Support for both J2SE 1.4.2 and 1.5 (development and debugging).
  • Support for both J2EE 1.3 and 1.4 (Servlet and/or EJB development, deployment, and debugging).
  • The ability to create, test (with the Eclipse web-service validation tools plug-in), and consume web services.
  • Project builds that support Ant, but the Eclipse IDE is required for all software builds.
  • Code refactoring.
  • Code profiling with the appropriate plug-in, such as that available from SourceForge (http://sourceforge.net/projects/ eclipsecolorer/).
  • Code formatting using predefined, customizable code styles.
  • The normal code-editing features, such as those supported by NetBeans.
  • A code outline component similar to the NetBeans Navigator that lets you browse code.
  • Support for programming languages and environments other than Java.

The Eclipse UI (Figure 2) is just as attractive and efficient as NetBeans. However, there are more options available to customize the look-and-feel in Eclipse, such as view-specific fonts, the tab layout, and whether to display text in tabs. The fact that Eclipse breaks up the display into perspectives (different screen component layouts) is both a plus and minus. For example, I find it useful to have separate perspectives for debugging and coding, but some people may find this confusing. However, if you're developing in different languages or want to alter the display when debugging to emphasize (say, the call stack instead of the code editor), then having separate perspectives is a necessity.

In terms of performance, the one area that Eclipse outperformed NetBeans was on startup time. In all cases (with and without a project open), it took noticeably less time for Eclipse to start. However, the difference was nominal, and its significance questionable in the bigger picture. My overall opinion is that both Eclipse and NetBeans can afford quicker startup times.

Standard Java Development (J2SE)

Both Eclipse and NetBeans support Java development using multiple JDK versions, including 1.4.2 and 5.0. With Eclipse, you can add new Java runtime environments in the Preferences dialog box, available through the menu titled Windows. Within the Preferences dialog box, expand the Java entry within the tree list, and click on Installed JREs. Here, you can add JDK/JRE entries, and set one as the default for new projects.

With NetBeans, you add versions of the JDK (and set a default for new projects) via the Java Platform Manager, available from the Tools menu. Because NetBeans contains substantial support for desktop and mobile Java development, you can add development platforms for both J2SE and J2ME developments via this dialog box.

The process of starting a new J2SE development project in both Eclipse and NetBeans is similar. To start, choose the New Project menu item from the File menu, available in both IDEs. With NetBeans, select the project type by choosing an item listed in the Categories list. The General category is for standard desktop Java applications, or plain-old Java object (POJO) development. With Eclipse, select the Java Project option within the Wizards tree list.

After you enter a project name and select a project directory, the project is opened within each IDE's project display (see Figure 3). Both IDEs do a good job of displaying the component of projects, either by source packages or by folders that you create within each project. The NetBeans Projects display lists components mainly by their package type, while the Files display is a straightforward folder/file list. Eclipse does the same via its Package Explorer and Navigator views, respectively.

Project components are broken out differently depending upon the project. For instance, a web-application project includes additional tree nodes for web pages, web services, and web configuration files. There's also an extensive use of icons within the different parts of a project to help you quickly navigate through the various components at a glance.

It all comes down to editing code—but before you actually start typing, you need to know where to start. Both IDEs offer visual code browsers that let you quickly locate classes, methods, and fields within a project without scrolling through numerous source files. In NetBeans, it is the Navigator display, while in Eclipse it is the Outline view, as in Figure 4. In both cases, class members are displayed with icons that indicate public or private access, static or final declaration, or in the case of Eclipse, whether a method contains errors or warnings. NetBeans includes an inheritance tree within the display, whereas Eclipse uses a separate component, the Hierarchy view, to accomplish this.

Both IDEs have similar code-editor features, such as syntax-specific fonts and colors, code folding, bracket and parentheses matching, and warning/error indicators. Code folding lets you collapse portions of your code to one summary line, such as import lists, comment blocks, and entire function definitions. Both IDEs represent folding with an indicator placed within the editor's left margin, as well as with an ellipsis ("...") in the folded code itself.

Warnings and errors are indicated, in real time, as you write code within the editor's margin. When you hover (with the mouse) over the indicator in the margin, a tooltip is displayed with the problem description. Both NetBeans and Eclipse offer solutions to the problem when you click on the margin, although I found Eclipse to be more thorough and accurate in its resolution options.

To avoid errors and reduce typing, both IDEs support what is called "auto completion." If you type a class or object name, for example, the autocompletion feature displays the appropriate method or field names that apply. As you scroll through the list of methods and fields, the associated Javadoc entry is displayed. You can choose a method or field from the list displayed, or you can narrow down the choices by typing the beginning letters of the method or field you're looking for. After choosing a method, the display shows the parameter list, highlighting the next parameter with each comma you type. This functionality is almost identical for both NetBeans and Eclipse.

Once you are done editing and have all syntax-related errors cleaned up, it's time to get the bugs out by stepping through portions of your code. Both IDEs support source-level debugging for all Java projects, although Eclipse requires the appropriate plug-ins for JSP, Servlet, and EJB debugging. The plug-in you use to accomplish this is usually the one that comes with the application server you are deploying to (such as BEA WebLogic). NetBeans comes installed with built-in support for Tomcat and Sun Java System Application Server for J2EE project debugging. While this is an advantage for NetBeans users in that it eliminates set-up, Eclipse plug-ins make it possible to develop and debug with languages and platforms not supported by NetBeans (such as C++).

Both IDEs show where breakpoints are set with an indicator in the editor's left margin. You can set absolute breakpoints (where execution stops at a line of code) or conditional breakpoints (where execution stops when a condition is met). There is support for stepping into method calls as well as over them, jumping out of methods, and "run to cursor," where the code executes until it reaches the selected line of code.

NetBeans and Eclipse both support built-in source-code version control. Eclipse supports only CVS by default upon installation, and NetBeans supports CVS, Serena PVCS, and Microsoft Visual SourceSafe (VSS). However, Eclipse also supports PVCS and VSS via plug-ins, such as those available from SourceForge (http://sourceforge.net/projects/pvcsplugin/, and http://vssplugin .sourceforge.net/). Most source-code control vendors—such as Perforce, Subversion, Mavin, and Microsoft—offer Eclipse plug-ins for their tools as well.

To connect to a CVS repository in Eclipse, for example, you switch to the CVS Repository Exploring perspective. Once there, right-mouse click in the CVS Repositories view, and choose the New->Repository Location menu options. When the Add CVS Repository dialog appears, enter the appropriate CVS information, and click Finish. NetBeans has a similar CVS setup dialog box, accessible through the Versioning Manager, which is available from the Versioning menu. Both IDEs let you easily add new projects to the version control system you choose, or to pull an existing project from version control.

Enterprise Java Development (J2EE)

Enterprise Java development has long been the domain of expensive IDEs, such as Symantec's Visual Café, Borland's JBuilder, and Oracle's JDeveloper. However, with open-source IDEs such as Eclipse and NetBeans supporting the development, deployment, and debugging of J2EE applications, the barriers to entry have been removed. Once again, plug-ins let Eclipse work with just about any available application server. There is built-in support for Tomcat and any J2EE-compliant application server such as BEA WebLogic, JRun, and JOnAS. Additionally, there are plug-ins available from vendors or open-source projects such as SourceForge/ObjectWeb (http://forge.objectweb.org/projects/lomboz/) and Sysdeo (http://www.sysdeo.com/).

The Preferences dialog is where you configure Eclipse to work with the appropriate application server. This shows that there are various application server plug-in entries, such as Tomcat and WebLogic (which is chosen). For the WebLogic plug-in, you need to enter WebLogic-specific information, the Java classpath, and the Eclipse project(s) it applies to. Each plug-in has its own set-up requirements, but the paradigm is generally the same.

To add a new application server runtime environment, such as for WebLogic, click on the Add button within the Server...Installed Runtimes preferences. Next, choose from the available server types and enter the appropriate directory and classpath information. Finally, when you create a J2EE project in Eclipse, you need to tell it which application server runtime to deploy to and run within. To do this, right-mouse click on the project name and select the New menu. Next, choose the menu option Other, then choose Server Wizard from the dialog box that appears. At this point, choose from the preconfigured J2EE application server runtimes that you created previously.

NetBeans comes with built-in project configurations for Tomcat as well as Sun Java System Application Server 8.1. You can add support for just about any Java application server via the Server Manager interface, available from the Tools menu. Here, you can modify the settings of existing server definitions or add new ones via the Add Server button.

The NetBeans Runtime display component provides a global view of the available servers, running processes, configured databases, web servers, source control definitions, and web services defined in your development environment. The display also lets you add new servers, start/stop existing servers, connect to databases, and add web services. Additionally, you can view a database's tables and stored procedures, create new tables, and execute queries. This feature is useful as it allows you to stay within the NetBeans IDE even when you need to modify a data model or test a query or stored procedure.

Web-Service Development

Web services can be created only within an Enterprise project in NetBeans. To create one, right-mouse click on the project name, and choose the New->Web Service menu option. A dialog box appears for you to enter the service name, the package, and location. You can choose to create one from scratch or start from an existing class or WSDL definition. The new service is listed within your project under the Web Services folder. To add a new operation, right-mouse click on the web-service name and choose Add Operation. Figure 5 is a project with two web services created (HotelWS and RestaurantWS), each with its available operations.

With NetBeans, making a call to a web-service operation is simple. In an Enterprise application with a Servlet, for example, you begin in the Servlet's Java class. In the code where you wish to call into a web service, right-mouse click in the editor, and choose Web Service Client Resources->Call Web Service Operation from the popup menu. The available web services for your environment are displayed, along with their respective operations. Selecting an operation inserts the code needed to call into that web service and handle the response.

Although Eclipse doesn't make it as easy to consume a web service as NetBeans, it does have a visual web-service definition tool, called the WSDL Editor. The tool (Figure 6) lets you visually define the WSDL for your web service. You can map whole web-service definitions to messages, specify the SOAP bindings and port types, add new operations, and define new inputs and outputs.

Mobile Java Development (J2ME)

NetBeans has built-in support for J2ME Mobile Java application development (MIDP). Likewise, Eclipse supports J2ME development with the appropriate plug-in. Typically, you can get a plug-in from a phone vendor, such as Nokia. For this article, I worked with Nokia's Developer Suite for J2ME (http://www.eclipse- plugins.info/eclipse/plugin_details.jsp?id=712). The plug-in lets you build J2ME projects within Eclipse, and comes with emulators for the Nokia Series 60, Series 90, and 6320 models.

The Nokia Eclipse plug-in adds a new project type, a MIDP Project, and adds a toolbar to the IDE. With it, you can define new packages, new MIDP classes, phone deployment parameters, and emulator configurations. When debugging, Eclipse starts the appropriate emulator and allows you to step through code seamlessly. UI development, however, is not done in Eclipse, but is done through the standalone Nokia development suite installed with the plug-in.

NetBeans, however, has a J2ME UI development tool built-in—the Screen Designer. The tool lets you add menu commands (such as OK, Exit, Back, and so on), lists, text boxes, alerts, gauges, images, and other UI elements appropriate for mobile application development. When you add UI elements, NetBeans automatically generates code to handle the component actions. You need to add the implementation, but all the skeleton code is created for you.

With the NetBeans Flow Designer (Figure 7), you design the flow of a J2ME application's screens based on user actions. You can visually specify exactly what happens as users choose certain commands, enter data into a form, or choose entries from a list, for example. Doing this visually lets you quickly arrange and rearrange an application's UI behavior without touching any code. Of course, you can still get to the code by switching the editor to the Source view at the top of the editor window. You can toggle a single Java source file between the Source view, Screen Designer view, and Flow Designer tool as you see fit; actions taken in any view affect the same source module.

NetBeans supports J2ME application debugging and comes with a built-in smart phone emulator (Figure 8). You can interact with the application as you would on the real phone. Button and menu selection, and text entry, can be performed using the PC mouse and keyboard. As with Eclipse, you can download development tools from a specific cell phone vendor, such as Nokia, that integrate with NetBeans and include your target phone's emulator.

Conclusion

Comparing IDEs such as Eclipse and NetBeans is similar to comparing development languages—there is no winner. Both IDEs are competent development platforms for J2SE, J2EE, and J2ME development. Choosing between them largely comes down to taste, influence by others, and whether you develop in other languages in addition to Java.

DDJ


Related Reading


More Insights






Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

 
Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.