Java: NetBeans 4.0 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),
JBuilder (free intro version, otherwise expensive) or Eclipse (free), but it
has other advantages: cheaper in the case of IntelliJ IDEA and JBuilder,
and a reasonable GUI form editor, which Eclipse lacks (altho perhaps this has been added by now).
Overall a good choice.
The most useful feature for
students is the jagged red line put under erroneous statements when there's
a pause in the typing. I've gotten used to this feature so much that I feel
uneasy when I use an editor that doesn't have this feature.
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 1 with NetBeans 4.0 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.0
- 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.
Bugs in NetBeans 4.0
No console input area!
Misc tasks in NetBeans 4.0
- 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 Running Project 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.]