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.
Sun has recently begun freeing their Java implementation
and thereby opening the way for free software developers
to create an entirely free implementation of Java.
This free form is now available as the
OpenJDK. On Ubuntu, this is available 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
tools like NetBeans.
Install the Sun JDK installation like this:
The installation of some of these requires agreeing to
a 'Distributor License' twice:
First, press the TAB key to highlight OK, then Enter.
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, not.
You 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' full-featured community-based
Integrated Development Environment (IDE) for a variety of software
development interests including a Java Visual GUI editor,
Web developement for Java, Php, Ruby, 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.9-ml-javase-linux.sh
Install into a system directory ("/usr/local" by default)
by executing and following the installation wizard:
$ sudo sh netbeans-6.9-ml-javase-linux.sh
A NetBeans executable shortcut can be found in the
Applications Programming menu.
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.
Select File New Project
In the New Project window,
select the Java category,
and choose Java Application, then Next.
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.
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.
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.
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 ".".
Select File Save (or Ctrl-S) to save.
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.
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-6u18-docs.zip. For the sake of specificity, let's
say it is this:
/usr/local/share/docs/java/jdk-6u18-docs.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.