Detail steps to solve such problem on macOSX Catalina (or macOS-XI/11/X1 Big-Sur) is shown here https://apple.stackexchange.com/a/396025/133434
Summary:
• Download Java (JDK/SDK) version *.tar.gz
file that you need for macOS from OpenJDK site into default "~/Downloads"
folder, & verify its authenticity by comparing the OpenJDK site's shown SHA256 digest code, with the locally computed SHA256 digest code.
• Double-click on *.tar.gz
to decompress it, & with a privileged user access+Password allow macOS to decompress it, (you will need allow decompress from here: "System Preferences"
> "Security & Privacy"
> under "General"
tab > Goto bottomside section "Allow Apps Downloaded From"
> press the "Allow" or "Open anyway" button).
• Move the decompressed new jdk*.jdk
folder into "/Library/Java/JavaVirtualMachines/"
folder
& with a privileged user access+Password allow macOS to complete the move.
• In Terminal, run: $($(/usr/libexec/java_home --version 12.0)/bin/java -version)
& again specify a privileged user access+Password, to allow macOS "Open"/run it.
• From that point-on, that java
should work fine.
• before running a java based App, either setup the JAVA_HOME env var globally (see this) , or Use a shell-script: to select a specific Java version/folder before starting a specific java-based App.
if you're using Java 14, then change version number in above command, into --version 14.0
you can see all installed Java versions with: /usr/libexec/java_home -V
and avoiding brew
/Homebrew(pkg-mngr) based solution would be better choice1, 2, 3, 4, 5, 6, ..., users may use Macports(pkg-mngr), etc.