First, let's start by opening a terminal. Remember to use su or sudo for admin tasks.
sudo apt-get install sun-java6-jdk -y
You'll be asked to accept the accept the license terms before installing the JDK.If you're using Ubuntu 10.10, the word in bold should be maverick; for 10.4, use lucid.
After all is done, type the following to test your JDK:
java -versionjavac -versionMany Linux distributions come with other versions of the JRE (runtime environment). If this is the case, use the following terminal commands to choose which want to use as default:update-alternatives --config javaupdate-alternatives --config javacThe first line lets you choose a JRE and the second, a compiler (provided more than one alternative is installed).
Notes: You need the nonfree/multiverse repository(-ies) enabled. OR, if you're using Ubuntu 10.04 onwards, the "partner" repository (Sun's/Oracle's Java packages have been moved to partner). Via command line, you may easily do this by pasting the following line in your terminal:
sudo add-apt-repository “deb http://archive.canonical.com/ maverick partner”
sudo apt-get update