Enter this command in Terminal to see which version Java you have:
java -version
If you think you have several versions of Java installed on your computer, run the following command to see them:
ls /Library/Java/JavaVirtualMachines
After launching the Terminal application, enter the below command and hit Enter.
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk1.8.0_251.jdk (or other version)