The software packages you'll need are these installation files (from the course website).
netbeans-7.1-ml-javase-linux.sh (NetBeans)
jdk-6u30-apidocs.zip (Java Documentation)
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://www.oracle.com/technetwork/java/javase http://www.oracle.com/technetwork/java/javase/downloads
NetBeans http://www.netbeans.org http://www.netbeans.org/downloads/

JDK Installation

There is an open source version of JDK now available on Ubuntu as the openjdk-6-jdk package. My experience, however, is that the SUN JDK package is still a bit better, especially when used as the basis of other software packages.

As of Ubuntu 10.10, the SUN JDK package is no longer part of the standard Ubuntu repositories. You can address this issue by adding other necessary repositories:
$ sudo add-apt-repository ppa:sun-java-community-team/sun-java6
$ sudo apt-get update
Then install Sun JDK like this:
$ sudo apt-get install sun-java6-jdk 
This installation requires agreeing to a 'Distributor License' twice:
  1. First, press the TAB key to highlight OK, then Enter.
  2. Second, Press TAB key to get to "Yes", then Enter.

Make sure you have the right java

Open a terminal shell and execute these
$ java -version
$ javac -version
to make sure you're getting a "JDK6" version.
If, for some reason, this is not what you see, you will need to run change the Java alternatives. Do so by first running:
$ update-java-alternatives -l
The first entry on each line is the key. If necessary, set
$ sudo update-java-alternatives -s java-6-sun

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-7.1-ml-javase-linux.sh
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.

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 HelloWorld.java as part of the automatically-created package.
  5. Go to the Files view and observe the structure which NetBeans creates. The src folder is meant to hold all the source packages. The HelloWorld.java file is in a package directory helloworld within the src folder.

  6. Within the public static void main function, 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 HelloWorld.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 HelloWorld.jar found in the newly created dist directory. Afterwards, select Run → Run Main Project or F6, or the button.

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 command 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-6u30-apidocs.zip. For the sake of specificity, let's say it is this:
/usr/local/share/docs/java/jdk-6u30-apidocs.zip
Create this folder if it doesn't already exist.

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