From the official Oracle manual.
Navigate to
/Library/Java/JavaVirtualMachinesand remove the directory whose name matches the following format:/Library/Java/JavaVirtualMachines/jdkmajor.minor.macro[_update].jdkFor example, to uninstall 8u6:
%rm -rf jdk1.8.0_06.jdkDo 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.
To remove system files you need to add sudo before rm -rf command.
Answer from Danila Zharenkov on Stack OverflowFrom the official Oracle manual.
Navigate to
/Library/Java/JavaVirtualMachinesand remove the directory whose name matches the following format:/Library/Java/JavaVirtualMachines/jdkmajor.minor.macro[_update].jdkFor example, to uninstall 8u6:
%rm -rf jdk1.8.0_06.jdkDo 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.
To remove system files you need to add sudo before rm -rf command.
For MacOS - Big Sur | Using Terminal
I was able to remove OpenJDK as per information provided in below link.
Site Link

I installed several versions of the JDK, both official and open source. But I no longer need them. How exactly do you "uninstall" Java on macOS?
The best I can figure is just to go into HD/Library/Java and just delete everything there. Slightly new to macOS so wondering if this is right. The installers themselves don't give any means of uninstalling.
macos - Removing Java 8 JDK from Mac - Stack Overflow
macos - How to uninstall java from mac completely? JRE and JDK - Stack Overflow
How do I uninstall the Java JDK in macOS? - Stack Overflow
macos - How to remove OpenJDK and go back to regular JDK - Ask Different
Videos
I was able to unistall jdk 8 in mavericks successfully doing the following steps:
Run this command to just remove the JDK
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk<version>.jdk
Run these commands if you want to remove plugins
sudo rm -rf /Library/PreferencePanes/JavaControlPanel.prefPane
sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -rf /Library/LaunchAgents/com.oracle.java.Java-Updater.plist
sudo rm -rf /Library/PrivilegedHelperTools/com.oracle.java.JavaUpdateHelper
sudo rm -rf /Library/LaunchDaemons/com.oracle.java.Helper-Tool.plist
sudo rm -rf /Library/Preferences/com.oracle.java.Helper-Tool.plist
You just need to use these commands
sudo rm -rf /Library/Java/*
sudo rm -rf /Library/PreferencePanes/Java*
sudo rm -rf /Library/Internet\ Plug-Ins/Java*
To uninstall AdoptOpenJDK installed via Homebrew,
brew uninstall adoptopenjdk8
To uninstall OpenJDK installed via Homebrew,
brew uninstall openjdk8
The /usr/bin/java and other related tools are macOS shims that run a specific version of Java, as defined by the JAVA_HOME variable.
This variable is usually set in your ~/.bashrc file:
export JAVA_HOME=$(/usr/libexec/java_home -v1.8)`
You can check the current value:
$ echo $JAVA_HOME
/usr/local/Cellar/openjdk@8/1.8.0-392/libexec/openjdk.jdk/Contents/Home
You may have multiple versions of Java installed, to list them all:
$ /usr/libexec/java_home -V
Matching Java Virtual Machines (3):
21.0.1 (x86_64) "Homebrew" - "OpenJDK 21.0.1" /usr/local/Cellar/openjdk/21.0.1/libexec/openjdk.jdk/Contents/Home
17.0.9 (x86_64) "Homebrew" - "OpenJDK 17.0.9" /usr/local/Cellar/openjdk@17/17.0.9/libexec/openjdk.jdk/Contents/Home
1.8.0_392 (x86_64) "Homebrew" - "OpenJDK 8" /usr/local/Cellar/openjdk@8/1.8.0-392/libexec/openjdk.jdk/Contents/Home
/usr/local/Cellar/openjdk/21.0.1/libexec/openjdk.jdk/Contents/Home
In my case, you can see there are three versions of OpenJDK installed via homebrew. I can look them up in the list of installed packages:
$ brew list | grep -iE 'java|jdk|temurin'
openjdk
openjdk@17
openjdk@8
If I wanted to remove all of them, I could do brew uninstall them one by one, or:
(brew list | grep -iE 'java|jdk|temurin'); do brew uninstall $pkg; done
You can get official oracle instruction to remove java from macOS here
In your macOS terminal type this one by one
Copysudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefPane
sudo rm -fr ~/Library/Application\ Support/Oracle/Java
After that you can navigate to specific version of java that you intend to delete by using the following command:
Copycd /Library/Java/JavaVirtualMachines
Then type ls in your terminal to list down all the Java Virtual Machine Folders.
Finally add the version number you want to delete like this
sudo rm -rf jdk-10.0.1.jdk
Instead of jdk-10.0.1.jdk you can give any version number which are listed down in your above mentioned folder.
Update:
First remove the java runtime
Copy$ sudo mv /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin ~/ $ sudo mv /Library/PreferencePanes/JavaControlPanel.prefpane ~/Now you can close and reopen the System Preferences window to see that the icon is gone.
Next, uninstall the Java JDK. Open a terminal and change to the Java directory:
Copy$ cd /Library/Java/JavaVirtualMachinesYou can use
lsat the prompt to see what is in the directory and copy the jdk's path name with version number that you wish to delete.Copy$ ls --directory *jdk* examplejdk-7.jdkCopy the exact name of the path you want to remove -- for this example it's
examplejdk-7.jdk. Next, use that path name inside of single quotes ('examplejdk-7.jdk') to move it to your desktop. Instead of deleting the directory, this moves it to your desktop so you can restore it later in case there's an issue!Copy$ sudo mv 'examplejdk-7.jdk' ~/To confirm that it has been removed, run this command:
Copy
$ javaThis should output an error message:
No Java runtime present, requesting install
Steps I performed were from here : https://www.java.com/en/download/help/mac_uninstall_java.html
In the Terminal window Copy, Paste and run the commands below (one by one) :
sudo rm -fr /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin sudo rm -fr /Library/PreferencePanes/JavaControlPanel.prefPane sudo rm -fr ~/Library/Application\ Support/Oracle/JavaThen after successfully uninstalling Java, you may remove Java Deployment cache: In the Terminal window Copy and Paste the commands below:
rm -r ~/"Library/Application Support/Oracle/Java"then remove the jdk folder and it's content:
sudo rm -r -f /Library/Java/JavaVirtualMachines/jdk<"your_version">.jdkthen perform the holy computer restart .
If you have more than 1 java version installed you may also find useful the info from this page: https://java.tutorials24x7.com/blog/how-to-switch-java-version-on-mac
You can try removing Java from your system with these commands
rm will remove the specified file or directory.
options -r If it's a directory, it will remove all its contents recursively, including subdirectories/files and their contents. -f Do this forcefully without asking for confirmation for each files and folders.
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk[version].jdk
Example:
sudo rm -rf /Library/Java/JavaVirtualMachines/jdk-17.jdk
Additional Files/Folders
sudo rm -rf /Library/PreferencePanes/JavaControlPanel.prefPane
sudo rm -rf /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
sudo rm -rf ~/Library/Application\ Support/Oracle/Java