JDK/Netbeans on Windows
(last updated: Aug 31, 2009) print

Select font size:
The software packages you'll need are these installation files (from the course website).
jdk-6u14-windows-i586.exe (JDK: Java Development Kit)
netbeans-6.7.1-ml-javase-windows.exe (NetBeans)
jdk-6u10-docs.zip (Java Documentation)
The JDK package must be installed first. Windows systems come with the JRE (i.e., java and support executables), but not the compiler structure, (i.e., javac and others). These packages and other related ones are available from the respective home sites below. The Java site provides a cobundle version with JDK and NetBeans, but I prefer separate installations. The Java Documentation is not strictly necessary, but it is needed to provide online Javadoc reference in Netbeans.
SoftwareHomeDownload
Java http://java.sun.com http://java.sun.com/javase/downloads/
NetBeans http://www.netbeans.org http://www.netbeans.org/downloads/

Change the Folders View

Before you get going, tell Windows to stop treating you like a baby. Make it show you file extensions as well as other "hidden" features. Then, make these changes (most importantly, the first one):

JDK Installation

Before installing a newer version, you have to decide whether to remove or retain older versions of JDK and/or JRE (Java Runtime Environment). I tend to favor removing them, but if you're unsure, keep the older versions.

Java self-installs into the directory (assuming C:\ is the system drive root):
C:\Program Files\Java\jdk1.6.0_14
The freely-distributable JRE is also installed in the adjacent directory:
C:\Program Files\Java\jre1.6.0_14
From the Java site, you can alternatively choose between online and offline installations. The former downloads only a stub to your computer, and the more significant downloads occur during installation.

Shell Execution

If you want to run the Java applications from a command shell, you will probably need to set the PATH and CLASSPATH environment variables. The PATH specifies the list of folders searched for executables. The CLASSPATH specifies the list of folders and archives containing Java classes.

The environment variables can be manipulated through this access method:
Control Panel System Advanced Environment Variables
You want the PATH variable to contain the following directory
C:\Program Files\Java\jdk1.6.0_14\bin
When you edit the PATH variable, scroll to the far left append to the front this syntax:
C:\Program Files\Java\jdk1.6.0_14\bin;
You probably want the CLASSPATH environment variable to be unset, or cleared. Installed software packages may have automatically set this variable, leaving it unusable for shell execution. You may want to record CLASSPATH's current value so that you can restore it if something else goes wrong later.

If you're unsuccessful in either compilation or execution of a Java application from a shell, you should double-check the values of these two important environment variables by typing:
set PATH
set CLASSPATH
You can unset the CLASSPATH for this current shell invocation by doing
set CLASSPATH=
(with no blanks or other whitespace following the "=").

Netbeans Installation

NetBeans is SUN Microsystems' community-based Integrated Development Environment (IDE) for a variety of software development interests including Java, Php, C/C++, etc. The download site offers a bewildering array of choices of Netbeans, they are differentiated by a "download-type" term embedded in the download file. I generally prefer to be minimalistic and augment the features as needed. Other features can easily be added through Netbean's plugin facility or by separate downloads. The download type I'm using is javase as seen in the file:
netbeans-6.7.1-ml-javase-windows.exe
Install by executing and following the installation wizard. A NetBeans shortcut is created on the Desktop.

Configuration

You'll want to double-check that Java 1.6 is the platform being used by Netbeans. Open Tools Java Platforms and make sure the default is JDK1.6.

Most configuration settings are done by activating Tools Options through the menu system. If this is not the case, and you've confirmed that you JDK1.6 is the "main" JDK on your system (Mac users, see above), then reinstall NetBeans — it should be able to pick up the 1.6 installation.

Line-height correction

Certain modifiable features may not be accessible through this configurator. For example, the editor's default line height has been known to be too large. To change this, you'll need to edit the file
org-netbeans-modules-editor-settings-CustomPreferences.xml
found in the folder (HOME is your home directory)
HOME\.netbeans\6.7.1\config\Editors\Preferences\
To reset the line height, add this XML entry within the editor-preferences tags:
<entry javaType="java.lang.Float" name="line-height-correction" 
      xml:space="preserve">
    <value><![CDATA[0.75]]></value>
</entry>

Hello World Program

NetBeans creates directories called src which consist of one or more package of Java source files along with other types of support files. The compiled classes are kept in a separate build directory.

To create a simple "Hello World" program, start up NetBeans and follow the steps below.
  1. Select File New Project
  2. In the New Project window, select the Java category, and choose Java Application, then Next.
  3. Choose the project name HelloWorld. The other settings have default values which you probably want to use. The project location cannot be an existing directory. NetBeans also pre-checks the boxes Set As Main Project and Create Main Class. Leave these checked. Click Finish.
  4. In the left-hand window there you can observe three views of the netbeans contents: Projects, Files, Services. For the most part you can work from the Projects view. In the Projects window you will see the file Main.java as part of the automatically-created helloworld package.
  5. Go to the Files view and observe the structure which NetBeans creates. The Main.java file is in a package directory helloworld within the src directory, meant to hold all the source packages.

  6. Within the public static void main function (not the Main constructor), type
    System.out.println("Hello World");
    
    Observe the various syntactic assists which the editor offers when you pause after typing a ".".
  7. Select File Save (or Ctrl-S) to save.
  8. There are several ways to compile and run this application. One way is to right-click on Main.java and select Run File from the popup menu. Look for the output in the Output window at the bottom.

  9. Another way to build and run the project is by selecting Build Build Main Project or F11. This operation goes a step further and archives the compiled classes into the jar file Hello_World.jar found in the newly created dist directory. Afterwards, select Run Run Main Project or F6.

Shell Execution

NetBeans makes it easy to run its applications through the shell, assuming that your java executable is accessible. First of all, you have to execute "Clean and Build" to create the JAR file. The output of this operation indicates what should be done. After doing so, open a shell and navigate to the dist folder in the HelloWorld. From this folder run:
java -jar HelloWorld.jar
The dist folder is meant to be for "distribution." NetBeans will put all relevant libraries in this folder as well so that this can act as a standalone executable which can run on any system which has JRE installed. All Windows systems will have it installed; the only hitch is making sure that the version is up to a suitable level.

Install Javadoc Documentation

Choose a permanent location in your system for the documentation zip file jdk-6u10-docs.zip. For the sake of specificity, let's say it is this:
My Documents\docs\jdk-6u10-docs.zip
In Netbeans, open Tools Java Platforms and select the Javadoc tab from the Java Platform Manager. Click the Add ZIP/Folder ... button and navigate to select the above zip archive.

To see what effect this has, right-click on the "println" portion of the statement
System.out.println("Hello World")
in the Main.java file. From the popup menu, select Show Javadoc.


© Robert M. Kline