How to install java 8 on Ubuntu 16.04

The Oracle JDK, includes a development environment for building applications with the Java programming language. Please be aware that some elements of the Oracle JDK are proprietary, meaning that there may be licensing implications with respect to applications you develop with it.

1. Install the software-properties-common package if you don’t already have it. This provides an easier way to add new repositories:sudo apt-get install software-properties-common2. Add the repository sudo add-apt-repository ppa:webupd8team/java3. Update the local package cache: sudo apt-get update4. Install the metapackage: sudo apt-get install oracle-java8-installerThis package will run an installer for The Oracle JDK 8, which is the current stable release. You may also replace java8 in the package name with java7 or java9 to install different versions, although these releases are not recommended for development.
5. Verify that Java and the Java compiler have been properly installed:java -version
javac -version
As of this publication, these commands should return the following:java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
javac 1.8.0_131
6. Since the PPA only provides an installer, and not updates for the JDK itself, you may want to delete it when you’re finished in order to keep your repositories organized:sudo add-apt-repository -r ppa:webupd8team/java
You can read the original article here.