The easiest solution I have found so far is using a great tool called Oraji which automatically does the configuration for you. Here is the brief excerpt from the install instruction created by the Oraji developer:
Download latest official 32-Bit Oracle JDK. File name should be jdk-... -linux-i586.tar.gz from http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
Install Oraji on Ubuntu:
sudo add-apt-repository -y ppa:neurobin/ppa
sudo apt-get update
sudo apt-get install oraji
Java Installation Instruction:
Run in terminal:
sudo oraji '/path/to/the/jdk_or_jre_archive'
or run
sudo /path/to/oraji /path/to/the/jdk_or_jre_archive
after giving the oraji script execution permission if you didn't install the script.
That's it. Now if you want to populate JAVA_HOME
and other environment variables run source /etc/profile
or logout and login.
For more info like Uninstall, Changing JDK version, just follow this nice tutorial by Oraji developers https://github.com/neurobin/oraji
Have a great day, guys!