Documentation Archive Developer
Search

Identifying Java on OS X

This Technical Note discusses the recommended ways to identify an OS X Java installation at runtime, as well as differentiating between the various Apple Java releases for OS X. It is targeted at developers who need to provide features or workarounds in their applications which are specific to the OS X platform, or to a particular Java release for OS X. End-user techniques for discovering installed versions of Java are not discussed.

Identifying OS X from Java

Apple has made a Java SE runtime available for OS X, beginning with version 10.0. Any pure Java application should run great on OS X, but there are times when you may want to know which platform your application is running on. For example, to handle the About, Preferences, and Quit menu items your application can use the com.apple.eawt APIs, but it should only call those APIs on OS X. There are a number of ways to detect the current platform, but the easiest and most reliable way is to check the standard os.name System property:

Listing 1: Detecting OS X in Java code.

public static boolean isOSX() {
    String osName = System.getProperty("os.name");
    return osName.contains("OS X");
}

This is the preferred method for detecting an OS X system, because it uses a standard System property with a known value.

Back to Top

Identifying a Java Version

The next level of granularity to examine is which specific Java version your application is running under. For example, perhaps you want to use Java 1.5-specific APIs, but remain compatible with Java 1.4. There's nothing special about this on OS X: as on any other platform, you need to check the java.version System property:

Listing 2: Detecting a Major Java Version.

public static boolean isJava15OrBetter() {
    String javaVersion = System.getProperty("java.version");
    String[] fragments = javaVersion.split("\\.");

    // sanity check the "1." part of the version
    if (!fragments[0].equals("1")) return false;
    if (fragments.length < 2) return false;

    // check if Java 1.5.x or higher
    try {
        int minorVers = Integer.parseInt(fragments[1]);
        if (minorVers >= 5) return true;
    } catch (NumberFormatException e) {
        // was not an integer
    }

    return false;
}

Note: If you intend to support multiple Java versions, be sure to compile with the -target <version> flag, where version is the earliest version you want to support (i.e. javac -source 1.4 -target 1.4 *.java).

Back to Top

Identifying a OS X Version from Java

Sometimes it is necessary to identify a major version of OS X to use a tool or a native library that requires a minimum version of OS X. The most reliable way to determine the OS X version is to use the os.version System property:

Listing 3: Detecting OS X in Java code.

public static boolean isSnowLeopardOrBetter() {
    String osName = System.getProperty("os.name");
    if (!osName.contains("OS X")) return false;

    // split the "10.x.y" version number
    String osVersion = System.getProperty("os.version");
    String[] fragments = osVersion.split("\\.");

    // sanity check the "10." part of the version
    if (!fragments[0].equals("10")) return false;
    if (fragments.length < 2) return false;

    // check if OS X 10.6(.y)
    try {
        int minorVers = Integer.parseInt(fragments[1]);
        if (minorVers >= 6) return true;
    } catch (NumberFormatException e) {
        // was not an integer
    }

    return false;
}

Back to Top

Identifying an Apple Java Version

While Apple does its best to make sure its Java releases track the latest Oracle releases, Apple software update schedules for OS X depend on many factors. Therefore, Apple does not necessarily ship a Java release for every Java version that Oracle does. It is also possible for Apple to release a Java update that fixes problems specific to Java on OS X before a new minor version appears from Oracle. In this scenario, there would would be two Java SE 6 releases for the same version of OS X with the same Java version number, and simply checking the java.version System property would not be adequate to determine which Apple release your application is running on.

Why should developers be concerned? If there is a problem specific to Java on OS X that is affecting your application, there are two likely solutions:

  1. Your application prompts the user to update their Java to a version you know fixes the problem.

  2. If the above is not an option, work around the problem in the release which exhibits it.

Either of these actions requires a way of specifically determining which Apple Java release your application is running on. There are a number of ways of doing this, but the recommended method is to analyze the java.runtime.version System property. Apple appends a release-specific version string to the end of this property that can be used to identify which Apple release you're using, regardless of the major/minor Java release numbers. Listing 2 illustrates how you might do this in your Java code.

Listing 4: Identifying a specific Apple Java release.

public static boolean isExactlyLeopardUpdate4() {
    if (!isOSX()) return false;

    String runtimeVersion = System.getProperty("java.runtime.version");
    if (!runtimeVersion.startsWith("1.5.0_")) return false;
    if (!runtimeVersion.endsWith("-304")) return false;
    return true;
}

Be sure to check against both the Java and Apple version substrings as in the example above. While highly unlikely, it's possible for more than one major Apple Java release (i.e. 1.3.x, 1.4.x, 1.5.x, 1.6.x) to have the same build strings at the end. Note that for additional robustness, this check is done in conjunction with the OS X check from Listing 1.

As with the previous code examples, this is the preferred method of determining which release of Java for OS X you're running, because it uses standard System properties.

mrj.version

Another System property provided by Apple, mrj.version, can be used to a similar end. However, it is a legacy system property dating back to the Classic Mac OS, and is not guaranteed to have a deterministic format through future releases. Furthermore, Apple is trying to stay as close to the standard Java functionality as possible. For these reasons, we recommend that you instead use the more standard os.name and java.runtime.version properties for Macintosh identification in all ongoing Java development, as outlined in this Technical Note.

Back to Top

Java Version Strings

In order to make use of the technique described above, you'll need to know the version strings for all Java releases on OS X. Tables 1 through 4 list the relevant System property values for all Java 1.3, 1.4, 5.0, and 6 releases, respectively, starting with Mac OS X 10.0. Java versions which shipped with a OS X release are listed under that corresponding version, with a dash under the "Java Release" column. Java releases which appeared as Software Updates and/or manual downloads are listed under the "Java Release" column, next to the version of OS X for which they were available.

Note: J2SE 1.4 was not available until Mac OS X Jaguar (10.2), J2SE 5.0 not until Mac OS X Tiger (10.4), and Java SE 6 not until Mac OS X Leopard (10.5).

Table 1 : J2SE 1.3 Releases on OS X

OS X Release Java Release java.version java.runtime.version
10.0 Mac OS X 10.0 1.3.0 1.3
10.1 Mac OS X 10.1 1.3.1 1.3.1-root-010902-18:51
  1.3.1 Update 1 1.3.1 1.3.1-root_1.3.1_020714-12:46
10.2 Mac OS X 10.2 1.3.1 1.3.1-root-010902-18:51
  1.3.1 Update 1 1.3.1 1.3.1-root_1.3.1_030709-15:51
10.3 Mac OS X 10.3 1.3.1 1.3.1-root_1.3.1_030912-19:52
  Java Security Update (4.0) 1.3.1_16 1.3.1_16-root_1.3.1_050825-11:50
10.4 Mac OS X 10.4 1.3.1_15 1.3.1_15-root_1.3.1_050320-16:33
  1.3.1 and 1.4.2 Release 2 1.3.1_16 1.3.1_16-root_1.3.1_050718-17:36 (PowerPC)
1.3.1_16-root_1.3.1_060113-11:57 (Intel)

Note: Mac OS X 10.4 for Intel contains a J2SE 1.3 runtime for PPC, but running it under Rosetta is unsupported.

Note: Mac OS X 10.5 and later do not include J2SE 1.3.

Table 2 : J2SE 1.4 Releases on OS X

OS X Release Java Release java.version java.runtime.version
10.2 Mac OS X 10.2 1.4.1_01 1.4.1_01-39
  1.4.1 Update 1 1.4.1_01 1.4.1_01-69.1
10.3 Mac OS X 10.3 1.4.1_01 1.4.1_01-99
  1.4.2 1.4.2_03 1.4.2_03-117.1
  1.4.2 1.4.2_03 1.4.2_03-117.1
  1.4.2 Update 1 1.4.2_05 1.4.2_05-141
  1.4.2 Update 2 1.4.2_05 1.4.2_05-141.3
  Security Update 2005-002 1.4.2_05 1.4.2_05-141.4
  Java Security Update (4.0) 1.4.2_09 1.4.2_09-233
  Update 5 1.4.2_12 1.4.2_12-269
10.4 Mac OS X 10.4 1.4.2_07 1.4.2_07-215
  1.3.1 and 1.4.2 Release 2 1.4.2_09 1.4.2_09-232 (PowerPC)
1.4.2_09-239 (Intel)
  Release 5 1.4.2_12 1.4.2_12-269
  Release 6 1.4.2_16 1.4.2_16-b05-303
  Release 7 1.4.2_18 1.4.2_18-b08-310
  Release 8 1.4.2_18 1.4.2_18-b08-310
  Release 9 1.4.2_21 1.4.2_21-b01-326
10.5 Mac OS X 10.5 1.4.2_16 1.4.2_16-b05-302
  Java for Mac OS X 10.5 Update 2 1.4.2_18 1.4.2_18-b08-314
  Java for Mac OS X 10.5 Update 3 1.4.2_18 1.4.2_18-b08-314
  Java for Mac OS X 10.5 Update 4 1.4.2_21 1.4.2_21-b01-324
  Java for Mac OS X 10.5 Update 5 1.4.2_22 1.4.2_22-b02-329
  Java for Mac OS X 10.5 Update 6 disabled disabled
  Java for Mac OS X 10.5 Update 7 disabled disabled
  Java for Mac OS X 10.5 Update 8 disabled disabled
  Java for Mac OS X 10.5 Update 9 disabled disabled
  Java for Mac OS X 10.5 Update 10 disabled disabled

Note: The "Java for Mac OS X 10.5 Update 6" release disables J2SE 1.4 by default, but leaves the existing 1.4 installation present.

Note: Mac OS X 10.6 does not include J2SE 1.4.

Table 3 : J2SE 5.0 Releases on OS X

OS X Release Java Release java.version java.runtime.version
10.4 5.0 Release 1 1.5.0_02 1.5.0_02-56
  5.0 Release 3 1.5.0_05 1.5.0_05-83
  5.0 Release 4 1.5.0_06 1.5.0_06-112
  Release 5 1.5.0_07 1.5.0_07-164
  Release 6 1.5.0_13 1.5.0_13-b05-241
  Release 7 1.5.0_16 1.5.0_16-b06-275
  Release 8 1.5.0_16 1.5.0_16-b06-275
  Release 9 1.5.0_19 1.5.0_19-b02-306
10.5 Mac OS X 10.5 1.5.0_13 1.5.0_13-b05-237
  Java on Mac OS X 10.5 Update 2 1.5.0_16 1.5.0_16-b06-284
  Java on Mac OS X 10.5 Update 3 1.5.0_16 1.5.0_16-b06-284
  Java on Mac OS X 10.5 Update 4 1.5.0_19 1.5.0_19-b02-304
  Java on Mac OS X 10.5 Update 5 1.5.0_20 1.5.0_20-b02-315
  Java on Mac OS X 10.5 Update 6 1.5.0_22 1.5.0_22-b03-333-9M3125
  Java on Mac OS X 10.5 Update 7 1.5.0_24 1.5.0_24-b02-357-9M3165
  Java on Mac OS X 10.5 Update 8 1.5.0_26 1.5.0_26-b03-376-9M3263
  Java on Mac OS X 10.5 Update 9 1.5.0_28 1.5.0_28-b04-382-9M3326
  Java on Mac OS X 10.5 Update 10 1.5.0_30 1.5.0_30-b03-389-9M3425

Note: Mac OS X 10.6 does not include J2SE 5.0.

Table 4 : Java SE 6 Releases on OS X

OS X Release Java Release java.version java.runtime.version
10.5 Java for Mac OS X 10.5 Update 1 1.6.0_05 1.6.0_05-b13-120
  Java for Mac OS X 10.5 Update 2 1.6.0_07 1.6.0_07-b06-153
  Java for Mac OS X 10.5 Update 3 1.6.0_07 1.6.0_07-b06-153
  Java for Mac OS X 10.5 Update 4 1.6.0_13 1.6.0_13-b03-211
  Java for Mac OS X 10.5 Update 5 1.6.0_15 1.6.0_15-b03-226
  Java for Mac OS X 10.5 Update 6 1.6.0_17 1.6.0_17-b04-248-9M3125
  Java for Mac OS X 10.5 Update 7 1.6.0_20 1.6.0_20-b02-279-9M3165
  Java for Mac OS X 10.5 Update 8 1.6.0_22 1.6.0_22-b04-307-9M3263
  Java for Mac OS X 10.5 Update 9 1.6.0_24 1.6.0_24-b07-330-9M3326
  Java for Mac OS X 10.5 Update 10 1.6.0_26 1.6.0_26-b03-384-9M3425
10.6 Mac OS X 10.6 1.6.0_15 1.6.0_15-b03-219
  Java for Mac OS X 10.6 Update 1 1.6.0_17 1.6.0_17-b04-248-10M3025
  Java for Mac OS X 10.6 Update 2 1.6.0_20 1.6.0_20-b02-279-10M3065
  Java for Mac OS X 10.6 Update 3 1.6.0_22 1.6.0_22-b04-307-10M3261
  Java for Mac OS X 10.6 Update 4 1.6.0_24 1.6.0_24-b07-334-10M3326
  Java for Mac OS X 10.6 Update 5 1.6.0_26 1.6.0_26-b03-384-10M3425
  Java for Mac OS X 10.6 Update 6 1.6.0_29 1.6.0_29-b11-402-10M3527
  Java for Mac OS X 10.6 Update 7 1.6.0_31 1.6.0_31-b04-413-10M3623
  Java for Mac OS X 10.6 Update 8 1.6.0_31 1.6.0_31-b04-415-10M3635
1.6.0_31-b04-415-10M3646
  Java for Mac OS X 10.6 Update 9 1.6.0_33 1.6.0_33-b03-424-10M3720
  Java for Mac OS X 10.6 Update 10 1.6.0_35 1.6.0_35-b10-428-10M3811
  Java for Mac OS X 10.6 Update 11 1.6.0_37 1.6.0_37-b06-434-10M3909
  Java for Mac OS X 10.6 Update 12 1.6.0_39 1.6.0_39-b04-442-10M4008
  Java for Mac OS X 10.6 Update 13 1.6.0_41 1.6.0_41-b02-445-10M4107
  Java for Mac OS X 10.6 Update 14 1.6.0_43 1.6.0_43-b01-447-10M4203
  Java for Mac OS X 10.6 Update 15 1.6.0_45 1.6.0_45-b06-451-10M4406
  Java for Mac OS X 10.6 Update 16 1.6.0_51 1.6.0_51-b11-457-10M4509
  Java for Mac OS X 10.6 Update 17 1.6.0_65 1.6.0_65-b14-462-10M4609
10.7 Java for Mac OS X 10.7 1.6.0_26 1.6.0_26-b03-383-11A511
1.6.0_26-b03-383-11A511c
  Java for Mac OS X 10.7 Update 1 1.6.0_29 1.6.0_29-b11-402-11M3527
  Java for OS X 2012-001 1.6.0_31 1.6.0_31-b04-413-11M3623
  Java for OS X 2012-002 1.6.0_31 1.6.0_31-b04-414-11M3626
  Java for OS X 2012-003 1.6.0_31 1.6.0_31-b04-415-11M3635
1.6.0_31-b04-415-11M3646
10.7/10.8 Java for OS X 2012-004 1.6.0_33 1.6.0_33-b03-424-11M3720
  Java for OS X 2012-005 1.6.0_35 1.6.0_35-b10-428-11M3811
  Java for OS X 2012-006 1.6.0_37 1.6.0_37-b06-434-11M3909
  Java for OS X 2013-001 1.6.0_41 1.6.0_41-b02-445-11M4107
  Java for OS X 2013-002 1.6.0_43 1.6.0_43-b01-447-11M4203
  Java for OS X 2013-003 1.6.0_45 1.6.0_45-b06-451-11M4406
  Java for OS X 2013-004 1.6.0_51 1.6.0_51-b11-457-11M4509
  Java for OS X 2013-005 1.6.0_65 1.6.0_65-b14-462-11M4609

Note: Java SE 6 for Mac OS X 10.5 is only available on 64-bit capable Intel Macs.

Back to Top

Document Revision History

Date Notes
2014-02-20 Version info for "Java for OS X 2013-005" and "Java for Mac OS X 10.6 Update 17"
2013-06-24 Version info for "Java for OS X 2013-004" and "Java for Mac OS X 10.6 Update 16"
2013-04-18 Version info for "Java for OS X 2013-003" and "Java for Mac OS X 10.6 Update 15"
2013-03-05 Version info for "Java for OS X 2013-002" and "Java for Mac OS X 10.6 Update 14"
2013-02-21 Version info for "Java for OS X 2013-001" and "Java for Mac OS X 10.6 Update 13"
2013-02-04 Version info for "Java for Mac OS X 10.6 Update 12"
2012-10-16 Version info for "Java for OS X 2012-006" and "Java for Mac OS X 10.6 Update 11"
2012-09-10 Version info for "Java for OS X 2012-005" and "Java for Mac OS X 10.6 Update 10"
2012-06-20 Version info for "Java for OS X 2012-004" and "Java for Mac OS X 10.6 Update 9".
2012-04-23 Version info for "Java for OS X 2012-002", "Java for OS X 2012-003", and "Java for Mac OS X 10.6 Update 8".
2012-04-04 Version info for "Java for OS X 2012-001" and "Java for Mac OS X 10.6 Update 7", updated OS version checks for robustness.
2011-11-10 Version info for "Java for Mac OS X 10.7 Update 1" and "Java for Mac OS X 10.6 Update 6".
2011-08-03 Version info for "Java for Mac OS X 10.7".
2011-07-05 Editorial
2011-06-29 Version info for "Java for Mac OS X 10.6 Update 5" and "Java for Mac OS X 10.5 Update 10".
2011-03-18 Fixing typo in Java SE 6 version table.
2011-03-08 Version info for "Java for Mac OS X 10.6 Update 4" and "Java for Mac OS X 10.5 Update 9".
2011-01-07 Adding architecture information for Java SE 6 on Mac OS X 10.5.
2010-10-20 Version info for "Java for Mac OS X 10.6 Update 3" and "Java for Mac OS X 10.5 Update 8".
2010-05-18 Many version updates to the 1.4, 1.5, and 1.6 tables for 10.4, 10.5 and 10.6. Changed Sun to Oracle, added section about how to find Mac OS X version, modernized examples, and fixed up some older platform names.
2008-05-07 Version info for Java for Mac OS X 10.5, Update 1
2008-01-08 Version info for Java for Mac OS X 10.5 and Java for Mac OS X 10.4, Release 6 (Tiger)
2007-04-26 Version info for Java for Mac OS X 10.4, Release 5 (Tiger) and Java for Mac OS X 10.3, Update 5 (Panther)
2006-04-17 Version info for J2SE 5.0 Release 4 (Tiger)
2006-01-12 Version info for J2SE 5.0 Release 3 (Tiger)
2005-09-21 Version info for 1.3.1 and 1.4.2 Release 2 (Tiger), Java Security Update v4.0 (Panther)
2005-05-05 Added version info (1.3.1, 1.4.2, 5.0/1.5) for Mac OS X 10.4
2005-02-25 New version string from Security Update 2005-002 (10.3.4+)
2004-10-05 Added version info for Java 1.4.2 Update 2 to Table 2
2004-08-10 Added version info for Java 1.4.2 Update 1 to Table 2
2004-05-26 revison information
2004-04-26 Unspecified content revisions.
2004-03-04 New document that discovering installed versions of Java for OS X from Java code.