I have tried with the commands
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt install oracle-java8-installer
but after I could see that Java was not installed on my ubuntu machine. It hits the error like unable to locate package oracle-java8-installer
sudo apt install oracle-java8-installer
reading package lists...done
Building dependency tree
Reading state information...Done
E:Unable to locate package oracle-java8-installer
How should I resolve this?
That PPA has been discontinued by its author because of changes in Oracle's legal terms for Java downloads.
Now to download the Oracle JDK you have to go through the Oracle Download page or use the OpenJDK builds (e.g. the ones provided by your distribution or the ones from AdoptOpenJKD).