You will first need to know which version of Ubuntu you are using, as the Java version is different for Ubuntu versions older than 7. If you have an older version (like 6.06 or 6.10) make sure that you have the Multiverse Repository enabled.
Open a Terminal window, enter the command "sudo apt-get install sun-java6-bin" and press enter, you will be asked to provide your password.
Note: for Ubuntu 6.06 and 6.10, type "sun-java5-bin" instead of "sun-java6-bin".
Accept by pressing Y and then enter.
Once you accept the installation, you will be asked to accept the Sun license agreement, select and .
Once the installation is finished, although it is not required, it is recommended to also install the Java plug-in for your web browser.
To do so, type the following command in the Terminal: "sudo apt-get install sun-java6-plugin" and press enter, you might be asked to provide your password again.
Note: for Ubuntu 6.06 and 6.10, type "sun-java5-plugin" instead of "sun-java6-plugin".