Home > Articles > Programming > Java

Editing and Refactoring Code in NetBeans

  • PrintPrint
  • Share ThisShare This
  • DiscussDiscuss
Close Window

Charlie HuntLudovic ChampenoisGregory CrawleyPatrick KeeganChristopher Webster 

Learn more…

Sorry, this author hasn't written any articles.

Sorry, this author doesn't have anything for sale.

Sorry, this author hasn't posted any blogs.

NetBeans IDE provides a wide variety of tools to support Java application development, but it is the Source Editor where you will spend most of your time. Given that fact, a lot of attention has been put into features and subtle touches to make coding faster and more pleasurable. This chapter covers the ins and outs of the Source Editor.
  • Opening the Source Editor
  • Managing Automatic Insertion of Closing Characters
  • Displaying Line Numbers
  • Inserting Snippets from Code Templates
  • Using Editor Hints to Generate Missing Code
  • Matching Other Words in a File
  • Generating Methods to Implement and Override
  • Creating and Using Macros
  • Creating and Customizing File Templates
  • Handling Imports
  • Displaying Javadoc Documentation While Editing
  • Formatting Code
  • Text Selection Shortcuts
  • Navigating within the Current Java File
  • Navigating from the Source Editor
  • Searching and Replacing
  • Refactoring Commands
  • Deleting Code Safely
  • Extracting a Superclass to Consolidate Common Methods
  • Changing References to Use a Supertype
  • Unnesting Classes
  • Tracking Notes to Yourself in Your Code
  • Comparing Differences Between Two Files
  • Splitting the Source Editor
  • Maximizing Space for the Source Editor
  • Changing Source Editor Keyboard Shortcuts

NETBEANS IDE PROVIDES A WIDE VARIETY OF TOOLS to support Java application development, but it is the Source Editor where you will spend most of your time. Given that fact, a lot of attention has been put into features and subtle touches to make coding faster and more pleasurable.

Code completion and other code generation features help you identify code elements to use and then generate code for you. Refactoring features enable you to easily make complex changes to the structure of your code and have those changes propagated throughout your project. Keyboard shortcuts for these code generation features and for file navigation ensure that your hands rarely have to leave the keyboard.

Architecturally, the Source Editor is a collection of different types of editors, each of which contains features specific to certain kinds of files. For example, when you open a Java file, there is a syntax highlighting scheme specifically for Java files, along with code completion, refactoring, and other features specific to Java files. Likewise, when you open JSP, HTML, XML, .properties, deployment descriptor, and other types of files, you get a set of features specific to those files.

Perhaps most importantly, the Source Editor is tightly integrated with other parts of the IDE, which greatly streamlines your workflow. For example, you can specify breakpoints directly in the Source Editor and trace code as it executes. When compilation errors are reported in the Output window, you can jump to the source of those errors by double-clicking the error or pressing F12.

In this chapter, we will demonstrate the ways you can use the IDE's editing features to simplify and speed common coding tasks.

Opening the Source Editor

Before starting to work in the Source Editor, you will typically want to have an IDE project set up. You can then open an existing file or create a new file from a template. See Chapter 3 for basic information on creating projects and files and for a description of the various file templates.

If you would simply like to create a file without setting up a project, you can use the Favorites window. The Favorites window enables you to make arbitrary folders and files on your system accessible through the IDE. The Favorites window is not designed for full-scale project development, but it can be useful if you just want to open and edit a few files quickly.

To use the Source Editor without creating a project:

  1. Choose Window | Favorites to open the Favorites window.
  2. Add the folder where you want the file to live (or where it already lives) by right-clicking in the Favorites window, choosing Add to Favorites, and choosing the folder from the file chooser.
  3. In the Favorites window, navigate to the file that you want to edit and doubleclick it to open it in the Source Editor.

    If you want to create a new file, right-click a folder node, choose New | Empty File, and enter a filename (including extension).

  • Share ThisShare This
  • Your Account

Discussions

I couldn't get this to work...
Posted May 2, 2010 09:43 AM by xandrani
0 Replies
program to detect USM
Posted Jan 6, 2010 09:37 AM by fostek2000
0 Replies

Make a New Comment

You must log in in order to post a comment.

Related Resources

Emily NaveCommunity Tips: Starting a User Group Library
By Emily Nave on August 3, 20102 Comments

The Central Penn Adobe User Group (CPAUG) uses a library program to share books from different publishers with members. A short Q&A with group leader Megan Fister provides some great tips for starting your own.

Keep going with GWT
By Federico Kereki on August 1, 2010 No Comments

I've been using GWT for some years now, and I'm still contented with the easier way for web development. After having written a book on GWT development, doing a blog seemed a good idea for answering questions, and for further expanding topics that didn't get a place in the book.

Emily NaveUser Group Organizations: Finding Support in the Greater IT Community
By Emily Nave on July 29, 20102 Comments

Birds of a feather flock together, right? If you’re already a member of an established user group or looking for other like-minded technology evangelists, connecting with peers is an important part of being an active voice in the IT community.

See All Related Blogs

Informit Network