Follow the steps to successfully install default JRE and default JDK in your Ubuntu
To check if Java is already installed:
If the above command returns “The program java can be found in the following packages”, then it means that Java hasn’t been installed, so execute the following command:
sudo apt-get update
sudo apt-get install default-jre
When prompted hit y, the installer installs jre.
To install the Java Development Kit (JDK), which is needed to compile Java applications execute the following command:
sudo apt-get install default-jdk
Hit y and continue..
Now check the version of Java installed.
To make sure that you are running the correct version of Java, execute the following and set your preference.
sudo update-alternatives –config java
For example, if you need default jdk, type 1 and press enter.