NetBeans 6.0: A First Look

NetBeans 6 is now in parity with Java Studio Creator in terms of Java UI and Ajax development


January 24, 2008
URL:http://drdobbs.com/jvm/netbeans-60-a-first-look/205918099

Eric Bruno is a contributing editor to Dr. Dobb's Journal. He can be contacted at www.ericbruno.com.


Sun Microsystems recently released NetBeans 6.0 which came with significant improvements, almost all in direct response to user requests. Even the developers who like NetBeans have posted complaints about its editor, especially when compared with Eclipse. These issues have been addressed, as have many others. Here is a list of the top areas of improvements:

Of course, the entire list is too comprehensive to cover in this article. However, let's explore the highlights, and those that were most requested by developers like you.

NetBeans Installation

The first point of frustration for any person downloading a software package that offers different configurations is the choice of which one to download. Should you download and install the complete package and potentially waste space and time? Or should you risk installing a subset only to require an additional feature set later on?

For convenience, NetBeans lets you choose from one of the most common configurations; see Figure 1. These include configurations for Java SE development, Web/Java EE development, C/C++ development, Ruby development, or all of the above. Coming soon are options that will include UML and Java ME.

[Click image to view at full size]
Figure 1 NetBeans offers a stress-free choice of downloads; you can easilychange it later, even after installation.

In fact, you can download the NetBeans options with all available packages, but only install a subset of components. With this, you can maintain one NetBeans package, yet allow different developers to install only the component subsets that they need.

Regardless of which components you choose to download and install, if your needs change later, it's not too late. The components for each of the standard configurations, and many more, are available for download through the NetBeans Plug-ins dialog; see Figure 2. Simply install all of the plug-ins for a particular category (such as the "Web & Java EE" category in shown) and it's as though you downloaded and installed that package right from the start.

[Click image to view at full size]
Figure 2: The NetBeans Plugins dialog allows you to download and install allavailable components at a later time.

Improving the NetBeans installation is important, but it's something you won't need to deal with much once it's complete. The changes that you'll appreciate every day are those Sun made to the NetBeans code editor.

NetBeans Code Editor

Of all the feedback Sun received regarding previous versions of the NetBeans IDE, the most common theme was that the editor did not compare well to the competition. As a result, Sun listened to the feedback and completely re-implemented the editor framework for NetBeans 6.

This includes enhanced syntax highlighting, such as special support for static variables, and using a strike-through for deprecated code (see Figure 3). However, other features go way beyond this. For instance, NetBeans has enhanced programming language awareness, whether you're writing code in Java, C++, Ruby, Groovy, or any other language for which a NetBeans plug-in exists. In fact, NetBeans 6 includes full-featured editor functionality for all supported languages in addition to Java, such as C++, Ruby, and even JavaScript. No longer are scripting languages treated as second-class; developers will enjoy all of the same NetBeans features they're used to using with Java when working with script code.

[Click image to view at full size]
Figure 3: Enhanced syntax highlighting includes distinct highlighting of static variables (italics), deprecated code (strikethroughs), and much more.

Enhanced syntax parsing occurs as you peruse your code, such as when you move the cursor around. For instance, when the cursor is moved to a bracket, the opposing bracket is also highlighted (if it's in view). The same goes for variables; all occurrences of the variable will be highlighted when the cursor is moved within it. This is a feature that's been available in NetBeans and other IDEs for some time. However, it's been greatly expanded in NetBeans 6.

Other enhancements include inline renaming, where changing method or variable names, for instance, is a snap. Simply move the cursor to the method or variable name to be changed, hit CTRL-R (or Command-R for Mac OS X), and then type the new name. All instances of the renamed element will be updated throughput your project.

Adding new code is easier in many cases as well. For instance, code insertion and code completion both work in context to where your cursor is. Code insertion is used to generate entire code constructs, such as getter and setter methods, constructors, and so on. Code completion will complete something you've begun to type, such as a try..catch block, or the use of an object. The enhancements in NetBeans 6 give you more control over the code that's inserted or completed within your project. Other enhancements include:

In addition to a full-screen editor view (where all other panes and menus are temporarily removed from sight), you can now undock editor windows and move them independently from the main NetBeans window, and any other undocked editor windows (Figure 4). I find this feature particularly helpful; one that I've wanted for a while now. For instance, it's very convenient to keep editors open on one monitor while I debug an application with the main IDE window on a second monitor.

[Click image to view at full size]
Figure 4: Individual editor windows can be undocked from the main IDE window, and then moved and sized independently. This feature is very convenient when used with multiple-monitor configurations.

Although many of the enhancements and additional features in the NetBeans 6 editor may seem minor, together they add up to a much-improved coding experience. I've personally seen my productivity grow as a result. However, the enhancements in NetBeans 6 don't stop at the editor; let's explore other areas of significant improvement.

NetBeans 6 Tools Support

Three areas of improvements worth noting regarding tools in NetBeans 6 are the Profiler, HeapWalker, and the integration of JMeter. Of course, NetBeans offers other tool support, such as JUnit for built-in unit testing, Ant for script-based system builds, deployment, and testing, as well as multiple source code control systems. First, let's look at the Profiler.

It's important to know how your code behaves as thoroughly as possible, even during the development cycle. This means you need to watch it in the debugger, force the execution of error handling code paths that otherwise get executed in rare conditions, and perform black-box testing. When those steps are complete, it's helpful to get a view of your code as it runs from the computer's point of view. This is where the code profiler comes in to play.

Code profiling measures the execution time of your code as methods are called, classes are loaded, and memory is allocated and freed. The Profiler tool that comes with NetBeans will do this for you when you choose the Profile Main Project menu option from the Project menu. After starting your application in the Profiler, exercise it as thoroughly as possible, as applicable to the area you're testing. Afterwards, NetBeans will display a graph that shows which classes and methods were called most, which code took the longest to execute, and so forth (see Figure 5). This is a tool that most developers should already be familiar with.

[Click image to view at full size]
Figure 5: The NetBeans Profiler displays code in graphs that highlight methodsthat are called most, and methods where the most time is spent (hot spots).

A new feature in NetBeans 6 lets you explicitly insert profile points (to measure execution time within a certain block of code) without requiring you to add invasive instrumentation code (see Figure 6). You can time the execution of code, or take snapshots of memory usage to perform deltas with at a later time. Profile points can be tied to specific lines of code, events that your code handles, or they can be time-based.

[Click image to view at full size]
Figure 6: You can insert profile points via this dialog, which is available when you right-mouse click on the line of code you'd like to profile, and choose the Profiling...Insert Profile Point option from the pop-up menu.

The HeapWalker tool, traditionally available as a standalone application with the JDK, is enhanced for use within NetBeans. With it you can monitor garbage collection, view which classes use the most memory in terms of percentage, instance count, or size in bytes (see Figure 7), and you can drill down into specific instances of a class and inspect its memory usage (see Figure 8).

[Click image to view at full size]
Figure 7: With the integrated HeapWalker tool, you can see your code categorised by instance count, size in bytes, or percentage of heap used.

The integration of Apache JMeter lets you perform server performance testing, for both static and dynamic web resources. All of the statistics are integrated with NetBeans' graphical profiler display.

[Click image to view at full size]
Figure 8: HeapWalker lets you drill down into specific class instances to get detailed memory usage information.

UML support has also grown in NetBeans 6. You can create projects based on UML, and then generate Java source code from the diagrams. New with this release, you can reverse engineer existing Java projects and create complete UML models from them. At that point, you can modify the UML, or the Java code, and the changes will be automatically round-trip integrated into the opposing view. The result is that both the Java code and UML models for your application will be kept in sync automatically. Additionally, the code that's generated is done so according to your customized code templates, and does not contain ugly code markers.

Other tools that are continually enhanced are the debugger and the GUI builder. For instance, with competing IDEs as well as previous versions of NetBeans, choosing to step over a line of source code that consists of multiple expressions (such as with if and for statements) would cause focus to remain on that line until all expressions were evaluated. With NetBeans 6, when you step over a line of source, all expressions are executed, and the focus moves to the next source line automatically. This feature alone is worth upgrading to NetBeans 6, in my opinion.

To aid in building applications with graphical user interfaces, new controls allow you to generate UI components directly from your data sources. From that point, the generated UI is automatically kept in sync with changes to the data source. Customizable boilerplate code is included to enable this feature.

Other Improvements

So far, we've examined enhancements and features added to NetBeans 6 mainly for the code editor and tools support. There are numerous important enhancements made throughout the rest of NetBeans that are worth reviewing.

NetBeans Project Improvements

For instance, NetBeans project support has been greatly enhanced with the ability to maintain multiple configurations per project. Each configuration is easily selectable via a drop-down combobox on the main toolbar for convenience (see Figure 9). With this feature, you can easily create multiple runtime configurations, such as those that stress your application in different ways, take different command-line parameters, and so on. Having the ability to define a default configuration, and quickly switch between others, will prove to be a valuable addition.

[Click image to view at full size]
Figure 9: You can easily create and choose from multiple project configurations from a combobox on the main NetBeans toolbar.

Other project-related improvements include the ability to create project groups, regardless of dependencies. With NetBeans 6, you can group projects any way you please.

NetBeans Local History

The addition of a local history of source code changes is significant, in my opinion. Although NetBeans supports many different source-code control systems, such as CVS, Subversion, and others like Perforce that provide appropriate plug-ins, there is a common usage scenario that these systems dont address well. In my experience, most development organizations maintain a "don't-break-the-build" policy where the rule is to never check code back into the main repository unless it compiles and has been unit tested. There is good reason for this: most organizations perform regular (sometimes daily) builds to deploy and test.

However, the problem with this approach is that some developers end up with code modules checked out for days or longer as they implement and unit test their new code. Since they're not checking in their code (for good reason) they run the risk of losing the code, or losing changes, through something as simple as a file overwrite. They also lose the ability to look back in time at previous local changes. NetBeans 6 provides a solution to this -- Local History.

As you make changes to a file and save them, NetBeans tracks them and creates a revision history complete with deltas maintained by date and time. Under the NetBeans main Versioning menu is a new choice called Local History. When chosen, a history list view is displayed for the selected file along with the differences between the current state of the file, and the revision of the file chosen in the list (see Figure 10).

[Click image to view at full size]
Figure 10: The NetBeans 6 Local History maitains a local cache of changes made to a file, complete with history and file differences.

While this feature doesn't replace the need for a full-featured source-code control system such as Subversion, it does fill in the void left when you make changes locally over the course of a number of days (by default, seven days worth of changes).

Easy JavaDoc Creation

JavaDocs can be created for you, as you type, or by hitting CTRL-Enter on a line of code. You can also generate JavaDocs for a complete class simply by selecting the Generate JavaDoc for menu option from the top-level Build menu. The result is a JavaDoc file, complete with frames, thats automatically opened in a browser for you to inspect (see Figure 11).

[Click image to view at full size]
Figure 11: Full JavaDocs are created automatically for your code either as you type, or through an option on the Build menu.

The resulting JavaDoc is clean and professional looking, and is a snap to generate. You no longer have any excuses not to include full JavaDocs with your code!

Web Services and Database Support

NetBeans 6 includes support for JSR 311, which standardizes REST-based web service development and deployment. A fully compliant JSR 311 plug-in is available to help you build lighter-weight, REST-based web services with Java and XML. Also included is a graphical SOAP-based web service designer tool.

Another requested feature addressed in this release is the addition of GUI-based database query designer. Remember Microsoft Access? Although the database itself wasn't perfect, its graphical query designer made database development and relationship mapping a snap. NetBeans 6 brings the power of the query design GUI to enterprise database development.

Conclusion

With this release, NetBeans 6 is now in parity with Java Studio Creator in terms of Java UI and Ajax development. In fact, you can expect to see more of a convergence of NetBeans with Studio Creator and Studio Enterprise in the future. Even Sun Studio, Sun's C/C++/Fortran development IDE and toolset, uses the NetBeans IDE for its development environment, and will reuse the NetBeans installation options when you install it.

This level of integration across all of Sun's development tools and IDEs is unprecedented. When you combine the tool and language support, the license offerings (CDDL, and GPL v2 plus the CLASSPATH exception), the supported operating systems (Solaris, Linux, Mac OS X, and Windows), and other available developer applications (such as OpenSolaris, MySQL, and PostgreSQL), Sun offers the largest degree of choice and flexibility for all types of development when compared with competing offerings.

Terms of Service | Privacy Statement | Copyright © 2024 UBM Tech, All rights reserved.