Today I tried installing JAVA in my new Ubuntu system and followed the conventional method of downloading it through ppa:webupd8team/java oracle-java8-installer following this link.
Even though I successfully installed the default JDK and JRE, I was not able to install Oracle JDK which was needed for Android Studio.
After some research, I found out through this link that as of April 16, 2019, you won't be able to download Oracle JDK without signing in to an Oracle account. This stackoverflow answer too helped me.
With all these help these are steps I followed to install Oracle JDK.
Download the latest JAVA 8 SE development kit from here after creating or signing in to the Oracle account.
Open your terminal and type
Untar Java in your new folder
$tar -zxf jdk-8u5-linux-x64.tar.gz -C /opt/jdk
I installed using these commands (don't forget to replace with the one you installed.)
$update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_<YourVersion>/bin/java 100 $update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.8.0_<YourVersion>/bin/javac 100
To set oracle JDK as the default JVM, run
$sudo update-alternatives --config java
and select the Oracle JDK that you installed. And also do the same for java compiler,
$sudo update-alternatives --config javac
Set the JAVA_HOME Environment Variable using the following commands.
$sudo nano /etc/environment
add this line
and save the file, exit. Now reload and check using,
$source /etc/environment $echo $JAVA_HOME
Check if the java version is right
Hope this helped you.