If you intend to update the JDK on macOS and install a new JDK, you may leave the old JDK behind.
Learn how to remove the old JDK.
Let's find out if there is an old JDK in the first place, and if so, how many.
Check with the following command.
$ /usr/libexec/java_home -V
Then, the following result will appear.
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (6):
12, x86_64: "OpenJDK 12" /Library/Java/JavaVirtualMachines/openjdk-12.jdk/Contents/Home
9, x86_64: "Java SE 9" /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home
1.8.0_131, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
1.8.0_112, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home
1.8.0_102, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home
1.8.0_92, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk/Contents/Home
If the * (n) * part of * Matching Java Virtual Machines (n): * in the first line of the result is (1), then there is no old JDK. If the number in parentheses is 2 or more, there are multiple.
In the previous example, there are six.
Uninstalling is very easy. Just erase it with the rm command. For the directory to be deleted, specify the part from * / Library / Java to .jdk *.
For example, try deleting JDK1.8.0_92. You can only delete it with administrator privileges, so add sudo to your head. When you execute it, you will be asked for a password, so enter the password you use to log in.
$ sudo rm -rf /Library/Java/JavaVirtualMachines/jdk1.8.0_92.jdk
I will check it.
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (5):
12, x86_64: "OpenJDK 12" /Library/Java/JavaVirtualMachines/openjdk-12.jdk/Contents/Home
9, x86_64: "Java SE 9" /Library/Java/JavaVirtualMachines/jdk-9.jdk/Contents/Home
1.8.0_131, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_131.jdk/Contents/Home
1.8.0_112, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home
1.8.0_102, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_102.jdk/Contents/Home
It's gone. If there is an unnecessary JDK, delete it by the same procedure.
If you cannot start Eclipse, rewrite the Java path of -vm in the Eclipse.app/Contents/Eclipse/eclipse.ini file.
Note: This is for those using Eclipse on macOS, but if you can't start Eclipse on Windows, check out eclipse.ini.
I will also write a reference for those who ask, "Is that really okay?"
This article is based on an article about Java 7 from Oracle.
http://docs.oracle.com/javase/7/docs/webnotes/install/mac/mac-jdk.html
I refer to the following sentences at the bottom of this page. If the link is broken, you will not know it, so copy it.
To run a different version of Java, either specify the full path, or use the java_home tool:
/usr/libexec/java_home -v 1.7.0_06 --exec javac -version
For more information, see the java_home(1) man page.
Uninstalling the JDK
To uninstall the JDK, you must have Administrator privileges and execute the remove command either as root or by using the sudo(8) tool.
Navigate to /Library/Java/JavaVirtualMachines and remove the directory whose name matches the following format:*
/Library/Java/JavaVirtualMachines/jdk<major>.<minor>.<macro[_update]>.jdk
For example, to uninstall 7u6:
% rm -rf jdk1.7.0_06.jdk
Do not attempt to uninstall Java by removing the Java tools from /usr/bin. This directory is part of the system software and any changes will be reset by Apple the next time you perform an update of the OS.
*The 7u4 and 7u5 releases were installed into a directory that does not follow this format. To uninstall 7u4 or 7u5, remove the 1.7.0.jdk directory from the same location.