Tuesday, May 15, 2012

NetBeans Usability Tips

Java IDEs have come a long way since the days of JBuilder (though JBuilder seemed like a welcome advance at the time). Today's Java IDEs (such as NetBeans, Eclipse, IntelliJ IDEA, and JDeveloper) are very advanced tools that most Java developers embrace for writing significant Java code. As advanced as these IDEs are, they all still have their own quirks and each seems better and easier to use when one understands some key tips (or "tricks") to using that IDE more efficiently. In this post, I look at some tips I have found useful when using NetBeans.

Disabling Automatic Scanning

A problem that can be especially onerous when using NetBeans on a large code base with many related projects open is the occasionally too-frequent automatic scanning that NetBeans performs. This is supposed to only occur intermittently and its intention is good, but sometimes the intended behavior's value is worth less than the performance-degrading cost justifies. Fortunately, this option can be disabled when its cost is greater than its benefit. In the NetBeans for PHP blog post Enable auto-scanning of sources - Scan for External Changes, Petr Pisl covers how to do this in NetBeans 6.9.

This feature is also supported in NetBeans 7.1 as shown in the following screen snapshot (window shown is accessible by selecting Tools ⇒ Options ⇒ Miscellaneous ⇒ Files).

If the benefits of automatic scanning are desired (because, for example, multiple people are changing source code underneath each other frequently or because different editors are being used on the same versions of files), but less of it is wanted, another tip is to reduce the number of NetBeans projects and files that are open in NetBeans.

Controlling Level of NetBeans Hints

NetBeans's Java hints can aid the Java developer in improving and modernizing his or her Java code. The hints cover topics as diverse as performance, safety, conciseness, coding standards, likely bugs, latest JDK standards, and best practices. I do not cover these useful hints in more detail here because I've already covered them in multiple previous posts. I introduced NetBeans hints and how to enable them , configure them as warnings or errors, and introduced seven of the most important hints in my blog post Seven Indispensable NetBeans Java Hints. In the blog post Seven NetBeans Hints for Modernizing Java Code, I discussed seven more hints that are useful for bridging legacy Java code forward to use the best features of newer SDKs (J2SE 5, Java SE 6, and Java SE 7). My post Creating a NetBeans 7.1 Custom Hint demonstrates writing custom hints to further expand NetBeans hinting capability beyond the out-of-the-box hints.

Setting Source/Target JDK Appropriately

In the blog post Specifying Appropriate NetBeans JDK Source Release, I looked at several advantages of setting the JDK level for the NetBeans projects' source/target JDKs appropriately. This can make a major difference for developers using JDK 7 as it helps the hints covered in the previous tip to show areas where pre-JDK 7 code can be migrated to JDK 7 constructs. However, even developers using JDK 6 or JDK 5 can find value to having this set appropriately. The appropriate setting not only advertises features that are available, but it also prevents developers from mistakenly using newer versions when they are not yet available in the actual version of code the developer should be using. NetBeans will warn the developer that certain features are not available for that JDK setting, so it is important to have it set properly.

Leveraging NetBeans Keyboard Commands

Whether it's vi, emacs, Eclipse, NetBeans, or any other editor, the masters of the respective editors know and frequently use keyboard commands to get work done quickly. NetBeans offers so many keyboard-based commands that it's difficult to summarize them. However, some good starting points include Highlights of NetBeans IDE 7.0 Keyboard Shortcuts and Code Templates, NetBeans Tips and Tricks, Keyboard Shortcuts I Use All the Time, NetBeans IDE Keyboard Shortcuts, and NetBeans Shortcut Keys. NetBeans even supports Eclipse key bindings!

Hiding Clutter and Noise with Code Folding

My preference is to have as clean of code as possible. Sometimes, however, I am forced to deal with code that has a lot of unimportant junk or noise in it. In such cases, NetBeans's code folding support is welcome because I can hide that noise. It would obviously better if I could remove the unnecessary noise and code folding can be abused, but I am appreciative of the feature when it's my only option for reducing clutter and noise so that I can focus on what matters. I discussed NetBeans code folding in further detail in the post NetBeans Code Folding and the Case for Code Folding.

Other NetBeans Tips

There are numerous other useful NetBeans tips available online.

Roman Strobl's NetBeans Quick Tips

In the blog he maintained while working at Sun Microsystems, Roman Strobl wrote several "NetBeans Quick Tip" posts (although dated [mid-2000s], several of these are still applicable):

  1. NetBeans Quick Tip #1 - Setting Target JDK.
  2. NetBeans Quick Tip #2 - Generating Getters and Setters
  3. NetBeans Quick Tip #3 - Increasing Font Size
  4. NetBeans Quick Tip #4 - Extending the Build Process
  5. NetBeans Quick Tip #5 - EOL Sweeper
  6. NetBeans Quick Tip #6 - Abbreviations in Editor
  7. Quick Tip #7 - Macros in Editor
  8. NetBeans Quick Tip #8 - Using Custom Folds
  9. Quick Tip #9 - Better Responsivenes of Error Marks and Hints
  10. NetBeans Quick Tip #10 - Diffing Two Files
  11. NetBeans Quick Tip #11 - How to Save As...
  12. Netbeans Quick Tip #12 - Fast Navigation to Methods and Fields
  13. NetBeans Quick Tip #13 - Define a Shortcut for Ant Target
  14. NetBeans Quick Tip #14 - Accessing Files Outside Projects
  15. NetBeans Quick Tip #15 - Adding Multiple Components with Matisse
  16. NetBeans Quick Tip #16 - Using Dependent Projects
  17. NetBeans Quick Tip #17 - Faster Building of Projects with Dependencies
  18. NetBeans Quick Tip #18: What to Do when Things Go Wrong?
  19. NetBeans Quick Tip #19 - Positioning without Guidelines in Matisse
  20. NetBeans Quick Tip #20 - Killing Processes
  21. NetBeans Quick Tip #21 - Achieving Same Size
  22. NetBeans Quick Tip #22 - Using Matisse's Connection Manager
  23. NetBeans Quick Tip #23 - Changing Code in Blue Guarded Blocks
  24. NetBeans Quick Tip #24 - Correct Javadoc
  25. NetBeans Quick Tip #25 - Case Insensitive Code Completion
  26. NetBeans Quick Tip #26 - Short Package Names
  27. NetBeans Quick Tip #27 - Implementing Abstract Methods
  28. NetBeans Quick Tip #28 - Configuring Derby Database in NetBeans 5.0
  29. NetBeans Quick Tip #29 - Monitoring HTTP Communication
  30. NetBeans Quick Tip #30 - When GroupLayout Fails
  31. NetBeans Quick Tip #31 - Changing the Look and Feel
  32. NetBeans Quick Tip #32 - Faster and More Stable Ruby Support
  33. NetBeans Quick Tip #33 - Show Error Using Keyboard
  34. Keyboard Shortcuts I Use All the Time
Other Posts on NetBeans Tips

Your Favorite NetBeans Tip or Trick?

What is your favorite NetBeans tip or trick?

3 comments:

Unknown said...

The Versioning support for any files. for example i am using SVN checkout source code. With NB IDE i can track inline code changes easily.

@DustinMarx said...

One of the features of NetBeans that I considered including in this post, but did not include because I realized I don't use it as much as the others, is NetBeans's ability to present code in HTML. Adam Bien has recently posted on this feature in the post Pretty Printing Java Source as HTML. Another idea is to print/save the HTML output as PDF. This is such a nice NetBeans feature that even Eclipse wants it!

@DustinMarx said...

The blog post Ten Time-Savers in NetBeans lists ten handy features of NetBeans including typing shortcuts, commenting out a block of code (Ctrl+Shift+C), global replace (Ctrl+R), automatic formatting (Ctrl+Alt+F), determining project hosting a file (Ctrl+Shift+1), closing all open files (Ctrl+Shift+F4), fixing import statements automatically (Ctrl+Shift+I), Javadoc auto-completion (Ctrl+Space), code insertion (Alt+Insert), and NetBeans's nifty differencing tool [Tools->Diff as shown in my post NetBeans 7.2: Generating (Introduce) Local Extensions].

The post is well worth checking out as it has brief commentary and numerous illustrations (screen snapshots) of each tip in action.