Videos
Factsheet
In a comment under @Thilo's answer, @mobibob asked how to set JAVA_HOME in your .bash_profile on a Mac. Answer:
export JAVA_HOME=`/usr/libexec/java_home`
This will dynamically assign to JAVA_HOME the location of the first JDK listed in the "General" tab of "Java Preferences" utility.
See Apple Technical Q&A 1170: https://developer.apple.com/library/content/qa/qa1170/_index.html
EDIT:
If you prefer parentheses to backticks for command substitution, this also works:
export JAVA_HOME=$(/usr/libexec/java_home)
As the message says, you have to go to Apple, not Sun, for Java on the Mac. As far as I know, Apple JDK 6 is installed by default on Mac OS X 10.6 (Snow Leopard). Maybe you need to install the developer tools from your Mac OS X installation DVD (the dev tools are an optional install from the OS DVD).
See: http://developer.apple.com/java/
NOTE This answer from 16 Oct 2009 is now outdated; you can get the JDK for Mac OS X from the regular JDK download page on Oracle's website now.
I tested this answer using a clean install of High Sierra 10.13.6. All updates from Apple were installed.
The downloads of the JDKs can be found at Java Downloads. I could not correctly view this site using Safari under High Sierra. Instead, I installed and used Firefox ESR (Extend Support Release). This link for Firefox download can be successfull viewed from Safari. The file I downloaded and installed was Firefox 115.16.1esr.dmg.
I tried JDK 23 by downloading and installing jdk-23_macos-x64_bin.dmg. This was not recognized by Java. Next, I tried JDK 21 by downloading and installing jdk-21_macos-x64_bin.dmg. This was recognized by Java.
Instructions for uninstalling a JDK can be found here. Personally, I just used the Finder to move the /Library/Java/JavaVirtualMachines/jdk-23.jdk folder to the Trash.
I tested by using the simple code given below. The code was stored in the file named Simple.java.
class Simple{
public static void main(String args[]){
System.out.println("Hello Java");
}
}
Example of testing is given below.
dmas-Mac:Desktop dma$ javac Simple.java
dmas-Mac:Desktop dma$ java Simple
Hello Java
BTW, I tested JDK 23 using macOS Monterey and did not encounter the problems that occurred with High Sierra.
I've successfully installed Java 21 from Microsoft on High Sierra.
$ java --version
openjdk 21.0.8 2025-07-15 LTS
OpenJDK Runtime Environment Microsoft-11933195 (build 21.0.8+9-LTS)
OpenJDK 64-Bit Server VM Microsoft-11933195 (build 21.0.8+9-LTS, mixed mode, sharing)
Java 25 has the some issue as mentioned above. It looks like the jdks have been build with a dependency to "chkstk_darwin" which ist not available in High Sierra.