In Ubuntu 9.10 Karmic Koala apt-get and the Synaptic Software Manager both install version 6.15.1 of Sun Java and the JDK, which are now out of date, and an old version of Netbeans,, so don't use "sudo apt-get install" for these.
Go to the Sun Java download page
http://www.java.com/en/download/manual.jsp
Select the non-RPM 32-bit or 64-bit self extracting file, download it and check the file size of the downloaded file. Doesn't matter where you download it.
Click on the link to installation instructions for the corresponding file.
An easier way to set executable permission is to right click on the file in the file browser (Nautilus) and click Properties, then on the Permissions tab, click the Execute checkbox.
To test, open a new terminal and type:
java -version
You should see Java version "1.6.0_18" etc.
If you don't, you probably need to add some lines, adjusted to suit your installation directories, to .bashrc and .bash_profile which are both hidden files in your home directory.
gedit .bashrc
Add the following:
export JAVA_HOME=/opt/java/64/jre1.6.0_18
export PATH=$PATH:$JAVA_HOME/bin
Then edit your .bash_profile file and insert the same lines at the end:
gedit .bash_profile
Open a new terminal window and test as above.
If all went well, in the Applications menu > System Tools, you should now have the Sun Java Control Panel.
You can repeat a similar installation procedure for the JDK and Netbeans where you mark the downloaded .bin file as executable and then execute it from a terminal window in the directory you want to install into, such as /usr/local.
After installing the JDK, add to your .bashrc and .bash_profile files a line similar to this:
export PATH=$PATH:/usr/local/jdk1.6.0_18/bin
Netbeans 6.8 seems to be able to set itself up ok without any editing and adds itself to the Applications Programming menu.