The issue which you are facing is because of the Open JDK installed. Please follow the below steps to resolve the issue:
(i) Download the Java using the below command:
wget http://download.oracle.com/otn-pub/java/jdk/8u151-b12/e758a0de34e24606bca991d704f6dcbf/jdk-8u151-linux-i586.tar.gz
sudo mkdir /usr/lib/jvm
cd /usr/lib/jvm
sudo tar -xvzf ~/Downloads/jdk-8u151-linux-x64.tar.gz
(ii) Now edit the Environment file using the below command:
vi /etc/environment
(iii) Add the below lines:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/jdk1.8.0_151/bin:/usr/lib/jvm/jdk1.8.0_151/db/bin:/usr/lib/jvm/jdk1.8.0_151/jre/bin"
J2SDKDIR="/usr/lib/jvm/jdk1.8.0_151"
J2REDIR="/usr/lib/jvm/jdk1.8.0_151/jre"
JAVA_HOME="/usr/lib/jvm/jdk1.8.0_151"
DERBY_HOME="/usr/lib/jvm/jdk1.8.0_151/db"
(c) Save the file and execute the below command:
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_151/bin/java" 0
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.8.0_151/bin/javac" 0
sudo update-alternatives --set java /usr/lib/jvm/jdk1.8.0_151/bin/java
sudo update-alternatives --set javac /usr/lib/jvm/jdk1.8.0_151/bin/javac