Java: NetBeans 4.1 IDE
NetBeans is a free, open-source, IDE which is available from Sun at
www.netbeans.org.
This is a reasonable choice, and liked by many programmers.
It isn't as full featured as IntelliJ IDEA (expensive) or Eclipse (free), but it
has other advantages: cheaper in the case of IntelliJ IDEA,
and a reasonable GUI form editor, which Eclipse lacks (altho perhaps this has been added by now).
Overall a good choice.
Immediate error messages. The most useful feature for
students is the jagged red line put under erroneous statements when there's
a pause in the typing. NetBeans continuously compiles the program as you're
typing it to alert you whenever there's an error.
It's like the continuous spell checking of some word processors.
I've gotten so used to this feature that I feel
uneasy when I use an editor that doesn't do it.
Indentation is a serious problem for beginning students.
Just right click the source code and choose
Reformat Code. It will reformat the entire file if nothing is
selected, otherwise only the selected text.
Downloading NetBeans
The easiest way to intall NetBeans and the lastest version of Java is to go
to java.sun.com/j2se/1.5.0/download.jsp
and click the Download JDK 5.0 Update 3 with NetBeans 4.1 Bundle button.
For some reason the combined Java+NetBeans bundle isn't available from the
NetBeans site, www.netbeans.org, where
you can download the two parts separately.
Tutorials
Go to www.netbeans.org for the most
current documentation. Some of the articles you can find there are listed below.
Starting a new project in NetBeans 4.1
- Click New Project in File menu or Welcome window.
- Choose Category General, and Project Java Application. Click Next.
-
- Choose a Project Name. This will become the name of the project,
a folder, and the package that the project is in. It's probably least
confusing to choose a lowercase name with no blanks (eg, prog1 or leapyear).
- Choose a Project Location. This is the folder in which your project folder
will be created. You can have many projects in this folder, so you can name
it something general like "cmis340", using the Browse button to find and/or
create the folder. The Project Folder field should now be automatically
set for you using a combination of the Project Name and Project Location.
- Check both Set as Main Project and Create Main Class.
The main class name is the part after the dot and defaults to "Main".
I usually change it to something more meaningful, eg, "LeapYear". Note
that class names should start with an uppercase character. This can be
that same as the Project Name or different, as you wish, but should start
with an uppercase character whereas the project name is better with a lowercase
character.
- Click Finish.
- The left panel now shows your project, and the right panel shows the source file.
Misc settings in NetBeans 4.1
- Reasonable editor settings (line numbers and tab size)
- To change editor settings.
- Click the Tools > Options menu item.
- In the Options tree in the left panel,
click on Editing > Editor Settings > Java Editor
- In the right panel, click on the Line Numbers check box.
An even easier way to turn on the line number option is to
right-click in the "gutter" to the left of the source listing.
A pop-up menu offers a choice of turning on/off line numbers.
- In the right panel, set the Tab Size to 4.
Sun recommends using 4, so why isn't this the default?.
- To make comments print darker
- Comments may print in such a light gray that they are unreadable.
To change this.
- Click the Tools > Options menu item.
- In the Options tree in the left panel,
click on IDE Configuration > System > Print Settings > Java Editor
- In the right panel, click on the Print Fonts and Colors "..." button on the right.
- Change the color to black (0,0,0) for both Block Comment
and Single-line Comment.
- Changing to generic, type-safe, data structures
- When compiling a program that uses non-generic data structures,
it's possible to accidentally add an element of the wrong type.
To alert you to places where this might be a problem, add
- Right click on the project in the Projects panel at the left.
- Select Properties at the bottom of the popup menu.
- Click on Build > Compiling Sources in the left panel.
- In the Additional Compiler Options, put
-Xlint:unchecked
and click OK.
- Importing packages into a project
-
To use other packages (eg, com.fredswartz.fmt), NetBeans has to know where
to find them. Here is the process.
- Right click on the project in the Projects panel at the left.
- Select Properties at the bottom of the popup menu.
- Click on Build > Compiling Sources in the left panel.
- On the right, click Add JAR/Folder....
- Select the appropriate jar file, click Open, then OK.
- Turning runtime assertion checking on
-
- Right click on the project icon in the Project panel at the left.
- Select
Properties at the bottom of the drop-down menu.
- Click on the
Run choice in the left panel.
- In the VM Options text field at the right, enter "-ea" (without the quotes).
[TODO: There should be info/link here about how to make a runnable jar with assertions turned on.]
- Making NetBeans load faster by disabling some modules
- Take a look at
NetBeans Startup Performance Tips for some good tips to improve startup
time. Worked well for me.
- NetBeans will generate getters and setters
- See
Generating Getters and Setters.
Console input fixed in NetBeans 4.1
Console input was broken in NetBeans 4.0, but has been
fixed again in 4.1.