Identifying Java on Mac OS X

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





Identifying Mac OS X in Java

Apple has shipped a J2SE release with every copy of Mac OS X, beginning with version 10.0. Any general J2SE application that is not release-specific should run just fine on Mac OS X, but there are times when you may want to know which platform your application is running on. A perfect example is the Application menu on Mac OS X: you write to the com.apple.eawt APIs to respond to the About, Preferences, and Quit menu items, but you only want this code activated on Mac OS X. There are a number of ways to do this, but the easiest and most reliable way is to check the standard os.name System property that is known to exist on every J2SE version on any platform:

Listing 1: Detecting Mac OS X in Java code.

String lcOSName = System.getProperty("os.name").toLowerCase();
boolean MAC_OS_X = lcOSName.startsWith("mac os x");

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

Back to Top 

Identifying a Java Version

The next level of granularity would be which specific J2SE version your application is running under. For example, perhaps you want to use Java 1.4-specific APIs, but remain compatible with Java 1.3. There's nothing special about this on Mac OS X: as on any other platform, you need to check the java.version System property. Listing 2 demonstrates how this might be done.

Listing 2: Detecting a Major J2SE Version.

String javaVersion = System.getProperty("java.version");
if (javaVersion.startsWith("1.4")) {
  // New features for 1.4
}

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

Back to Top 

Identifying an Apple J2SE Release

While Apple does its best to make sure its J2SE releases are properly synched with the latest Sun releases, we have our own release schedules, and therefore do not necessarily ship every J2SE release that Sun does. For example, the initial 1.4.2 release on Mac OS X was based on JDK 1.4.2_03. It is entirely possible for Apple to release a Java 1.4.2 Update that fixes problems specific to Java on Mac OS X before a new minor version (e.g. 1.4.2_04) appears from Sun. In this scenario, there would have been two J2SE 1.4.2_03 releases for Mac OS X in the wild, and simply checking the java.version System property would not be adequate to determine which Apple release your application is running on.

Why should this concern developers? If there is a problem specific to Java on Mac 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 shows it.

Either of these actions requires a way of specifically determining which Apple J2SE 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 J2SE release numbers. Listing 2 illustrates how you might do this in your Java code.

Listing 3: Identifying a specific Apple Java release.

String rtv = System.getProperty("java.runtime.version");

// Special code for initial Java 1.4.2 release on Mac OS X
// Incorporates platform-detection code from Listing 1
if (MAC_OS_X && rtv.startsWith("1.4.2")
&& rtv.endsWith("117.1")) {
  ...
}

Be sure to check against both the J2SE and Apple version substrings as in the example above. While highly unlikely, it's possible for more than one major Apple J2SE 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 to a similar end, this check is done in conjunction with the Mac OS X check from Listing 1.

Like the others above, this is the preferred method of determining what release of Mac OS X Java you're running, because it uses standard J2SE 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 J2SE 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 Mac OS X. Tables 1 through 4 list the relevant System property values for all J2SE 1.3, 1.4, 5.0, and 6 releases, respectively, starting with Mac OS X 10.0. Java versions which shipped with a Mac 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 Mac OS X for which they were available. Note that J2SE 1.4 was not available until Mac OS X Jaguar (v10.2), J2SE 5.0 not until Mac OS X Tiger (v10.4), and Java SE 6 not until Mac OS X Leopard (v10.5).


Table 1. Java 1.3 Releases on Mac OS X.

Mac OS X Release Java Release java.version java.runtime.version
10.0 - 1.3.0 1.3
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 - 1.3.1 1.3.1-root-010902-18:51
1.4.1 Update 1 1.3.1 1.3.1-root_1.3.1_030709-15:51
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 - 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: The "1.4.1 Update 1" release for Mac OS X Jaguar updated Java 1.3.1 as well, and therefore has an entry in Table 1.

Mac OS X Leopard does not include Java 1.3.

Table 2. Java 1.4 Releases on Mac OS X.

Mac OS X Release Java Release java.version java.runtime.version
10.2 1.4.1 [Initial Release] 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 - 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 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 - 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
10.5 - 1.4.2_16 1.4.2_16-b05-302

Note: The "Release 5" release for Mac OS X Tiger and "Update 5" for Mac OS X Panther updated Java 1.4.2 as well, and therefore has an entry in Table 2.

Table 3. J2SE 5.0 Releases on Mac OS X.

Mac 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
10.5 - 1.5.0_13 1.5.0_13-b05-237

Table 4. Java SE 6 Releases on Mac OS X.

Mac 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

Back to Top 

Document Revision History

DateNotes
2008-05-07Version info for Java for Mac OS X 10.5, Update 1
2008-01-08Version info for Java for Mac OS X 10.5 and Java for Mac OS X 10.4, Release 6 (Tiger)
2007-04-26Version 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-17Version info for J2SE 5.0 Release 4 (Tiger)
2006-01-12Version info for J2SE 5.0 Release 3 (Tiger)
2005-09-21Version info for 1.3.1 and 1.4.2 Release 2 (Tiger), Java Security Update v4.0 (Panther)
2005-05-05Added version info (1.3.1, 1.4.2, 5.0/1.5) for Mac OS X 10.4
2005-02-25New version string from Security Update 2005-002 (10.3.4+)
2004-10-05Added version info for Java 1.4.2 Update 2 to Table 2
2004-08-10Added version info for Java 1.4.2 Update 1 to Table 2
2004-05-26revison information
2004-04-26Unspecified content revisions.
2004-03-04Discovering installed versions of J2SE, Mac OS X from Java code.

Posted: 2008-05-07


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.