First, find out what JDK version that is installed on your computer. To do this, run the following command in the terminal.
If you have any JDK installed, the output will be something simular to this.
Matching Java Virtual Machines (3): 11.0.1, x86_64: "Java SE 11.0.1" /Library/Java/JavaVirtualMachines/jdk-11.0.1.jdk/Contents/Home 1.8.0_202, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_202.jdk/Contents/Home 1.8.0_51, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_51.jdk/Contents/Home
Then, if your want to use the Java 1.8, then you should execute.
export JAVA_HOME=`/usr/libexec/java_home -v 1.8.0_202`
Then you can check if the changes have been taking into effect by checking the java version: