NetBeans IDE 3.6 Quick Start Guide

This document takes you through the basics of using NetBeans IDE 3.6 by creating a simple Hello World application. This document is designed to get you going as quickly as possible. If you want a more detailed description of NetBeans IDE features, see the following documents:


Project Setup

Task Description
Create a new project
  1. Choose Project > Project Manager (Ctrl-Shift-N).
  2. Click New, give the project a name, and click OK.

Add a source directory

  1. Choose File > Mount Filesystem.
  2. Select the Local Directory node in the wizard that appears and click Next.
  3. On Select Items to Mount page of the wizard, create a folder on your system called src.
    Note: If you are on a Windows system, you cannot create a new folder in your My Documents folder.
  4. Select the folder and click Finish.
    The src filesystem node appears in the Filesystems window. The filesystem's sources are added to the project classpath.
    Note: Don't navigate into the src directory. Just select the src directory and click Finish.
Create a new package
  1. Right-click the src directory node in the Filesystems window and choose New > Java Package.
  2. In the name field, type hello and click Finish.
Create a new file
  1. Right-click the hello package's node in the Filesystems window and choose New > Java Main Class.
  2. In the name field, type HelloWorld and click Finish.

Editing Source Files

Task Description
Introduction

In this section, we will write the code for the HelloWorld application. We will use the following tools:

  • Code completion. The Source Editor parses all of the packages and classes in the classpath, including the standard JDK classes, and automatically suggests matching packages and classes as you type.
  • Abbreviations. The IDE includes abbreviations for many commonly used word combinations that expand to the full words when you press Space. For example, typing psf and pressing Space expands the abbreviation to public static final.
  • Fast Import. The Source Editor lets you automatically generate the import statement for any class.
  • Automatic formatting and error highlighting.

When you are done with this section, HelloWorld.java will look like this:

/*
 * HelloWorld.java
 *
 * Created on 16 November 2004, 11:52
 */

package hello;

import java.util.Date;

/**
 *
 * @author  me :-)
 */
public class HelloWorld {

    /** Creates a new instance of HelloWorld */

    public HelloWorld() {
    }

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        String date = new Date().toString();
        System.out.println("Hello world! It's " + date);
    }

}
Use code completion
  1. Place the cursor at the end of the public static void main(String[] args) { line and press Enter.
  2. Type String date = new Dat and wait. Within a second or two, the code completion box should appear, listing all of the JDK classes that begin with Dat. You can also manually open the code completion box by pressing Ctrl-Space.
    The Source Editor also shows the Javadoc description of each class, if available. The IDE extracts this description from the Javadoc comments in the source code. For more information on working with Javadoc documentation, see the Using NetBeans IDE guide.
  3. In the code completion box, scroll down to Date. Notice there are two Date classes in the classpath. Select either of the two and press Enter. - u
    Note: Unless you use a fully-qualified name for a class, the code completion box offers the methods of all classes with the same name. It therefore does not matter whether you choose java.sql.Date or java.util.Date from the code completion box in the step above.
  4. Type (. Notice the IDE automatically fills in the closing parentheses.
  5. Go to the end of the line and type a . after the closing parentheses. The code completions box opens listing all of the methods in the Date class. Deprecated methods are shown with a line crossed through them. Start typing toString to narrow the selection down, then select toString and press Enter.
  6. Type a closing ;.
View errors
  1. Notice that the line you just entered is underlined with a red line and has a icon in the left margin, meaning that it contains errors.
  2. Hold the mouse over the icon to view the error. Since you have not entered an import statement for the Date class, the file contains a cannot resolve symbol compilation error.

Create import statement

  1. Place the insertion point anywhere in the word Date and press Alt-Shift-I.
  2. In the Fast Import dialog box, choose java.util.Date and click OK. The import statement is created and the Source Editor no longer shows an error for the line.

Expand abbreviations

  1. Place the cursor at the end of the String date = new Date().toString(); line and press Enter.
  2. Type sout and press Space. The sout abbreviation expands to System.out.println("");
  3. Type Hello World! It's between the quotation marks (be sure to include a space after It's).
  4. After the closing quotation mark, type + date.

Reformat code

 

  • If the spacing for the comment line does not match the spacing for the rest of the file, press Ctrl-Shift-F to reformat the entire file. If any lines are selected when you press Ctrl-Shift-F, only those lines are reformatted.

Compiling and Running Your Program

Task Description

Compile the program

  • Choose Build > Compile (F9).
    The Output window opens at the bottom of the IDE and displays any compiler output, including compilation errors. You can double-click any error to go to its location in the source code.

Run the program

  • Choose Build > Execute (F6).
    The IDE runs the program and prints the output to the Output window. You should see the following message in the Output window (with a different date, of course):
    Hello World! It's Wed Dec 10 18:15:20 CET 2003 

Debugging Your Program

Task Description

Add a breakpoint to a file

  • Click in the left margin (Shift-F8) of the file on the System.out.println("Hello World! It's " + date); line.
    A red breakpoint icon appears in the margin and the line is highlighted.

Add a watch to a variable

  1. Right-click the word date in the String date = new Date().toString(); line and choose New Watch (Ctrl-Shift-F7).
  2. Make sure that the Watch Expression field contains date (with a lower case d) and click OK in the dialog box.
Start a debugging session
  • Choose Debug > Start Session > Run in Debugger (Alt-F5).
    The IDE runs the file until the breakpoint is reached. Use the debugger views at the bottom of the IDE to monitor your program's state, such as the value of the date variable (listed under both Local Variables and Watches).
Step through program execution
  • Use Step Into (F7) and Step Over (F8) to execute the program one line at a time.
Stop a debugging session
  • Choose Debug > Finish Sessions (Shift-F5).