Go to JDK download page.
Downloading the JDK can prompt you to login or create an account on Orcale site. After login you will be able to download the dmg. Install the dmg.
After installation the jdk will be installed at the following location: /Library/Java/JavaVirtualMachines:
Set the Java_Home path now. Run the following command:
export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.8.0_331.jdk"
The jdk1.8.0_331.jdk folder name in your case could be different.
JDK has been installed now.