With Ubuntu you get the choice of whether to install OpenJDK or Sun/Oracle Java. OpenJDK is available in the default repositories for Synaptic/apt-get and Sun/Oracle Java is not. So, it might be tempting to just use OpenJDK. And for many applications that would be fine. However, there are some Java extensions that are not included in OpenJDK which are included in the Sun/Oracle Java install.
If you still want OpenJDK over Sun/Oracle Java then simply drop to the command line and type sudo apt-get install openjdk-6-jdk openjdk-6-jre and apt-get will install OpenJDK for you. However, if you want Sun/Oracle Java then you can download the latest version from the website at http://www.oracle.com/technetwork/java/javase/downloads/jdk-6u27-download-440405.html (I never have much luck finding it in the repositories). Select the self extracting executable for either 32-bit or 64-bit Linux (not the RPM) and download it onto your computer.
Once you have the self extracting executable on your computer, you can run it by going into the directory where it is located (e.g. ~/Downloads) and in the command line type sudo ./jdk-6u27-linux-x64.bin (assuming that's the name of the file you downloaded) and watch it go. Once the install is complete, you'll notice a new java directory located in the directory where you ran the sudo ./jdk-6u27-linux-x64.bin command. Move that directory to /usr/lib/jvm by issuing the following command from the /usr/lib/jvm directory sudo mv ~/Downloads/jdk1.6.0_27 ./
If you look at the existing contents of the /usr/lib/jvm directory then you'll probably see some other java directories already in there and likely some symbolic links too. If one of those links is java-6-sun then delete that link by dropping to the command line and typing rm java-6-sun. Then type ln -s ./jdk1.6.0_27 java-6-sun.
Typically this is the point where you add Java to your path and set JAVA_HOME. You can still set JAVA_HOME by editing the .profile file in your home directory (e.g. ~/.profile) but Ubuntu uses something else to determine the path of Java. Ubuntu uses profiles to determine the pathing for all Java installs available on the system. To set your new Java install as the default in your profile drop to the command line and type sudo update-alternatives --config java and select the number next to your new version of Java to set the Java runtime preferences. Then type sudo update-alternatives --config javac and again select the number next to your new version of Java to set the Java compiler preferences.
To test out your install of Java, drop to the command line and type java -version. You should see the version of your new Java install returned. Now type javac -version and again you should see the version of your new Java install returned.