It has been a tough six months to be the Java on the Mac guy for O'Reilly Network. Like many of you, I've had the alpha, then beta developer previews of Java 1.4.1 for Mac OS X. On the one hand, this meant that we couldn't talk publicly about the new features or discuss the good and bad points of the release because anyone who downloaded the developer previews was under NDA. On the other hand, there was no point in writing more articles about Java 1.3.1 for the Mac because that bus is moving on.
The big news in this release, according to Apple Java Product Manager Allen Dennison, is "getting us up to date with the latest release of Java from Sun." Apple had two tasks in moving from the 1.3.1 version of Java to 1.4.1. First, there were 60 percent more classes from Sun in the 1.4 release. Second, Apple decided to do a major rewrite and clean up the technology underneath the release. The GUI was moved from Carbon to Cocoa. This decision was costly in terms of time, but means that Java applications look and feel more like native applications on Mac OS X.
The Java 1.4.1 release for Mac OS X is available from Apple using the Software Update. Check out the release notes, read the notes about QuickTime Java incompatibility, or just visit the Apple Java main page.
You may remember that Apple drew a line in the sand with the Java 1.3.1 release. They said that Java 2 would never be available on Mac OS 9 or earlier but that Mac OS X would ship with Java 1.3.1 included in every box. Similarly, Java 1.4.1 is available for download by all Jaguar users. As you'll see from some of the features described below, it is impractical for Apple to provide a Java 1.4.1 implementation for pre-Jaguar releases.
There are two important points to note in the availability of Java 1.4.1 to all Jaguar users. First, Apple has continued its commitment to providing a great Java implementation and widely distributing it on the platform. I can write a Java application and send it to my mom and know that she can run it on her iMac with my dad offering helpful advice like "just click on it." Second, for the first time, there will be two versions of Java available on the Mac. We haven't had to worry about more than one VM for a while. With this release, the Apple 1.4.1 JVM will be introduced while the 1.3.1 JVM so as not to break previously released Java applications.
The Java 1.4.1 release represents a major rewrite on Apple's part. The infrastructure has been completely rewritten. Apple's Dennison explains that "To get Java 1.3.1 working on OS X we created 900 classes in addition to the 1,800 classes that were part of the J2SE base. With the rewrite we are maintaining only 300 classes to support the 3,000 classes that are part of J2SE. If you go back to Mac OS 9, the number of classes we've provided compared to the J2SE base has gone from 175 percent to 50 percent to the current 10 percent."
Apple explains that taking the extra time now with this rewrite will make keeping up with Sun releases much easier. Cynics might note that Sun released the beta of Java 1.4 almost two years ago and the final release one year ago. Apple has been a year behind Sun with most of its Java releases and promised to try for 60 days after Sun in future releases. Dennison makes no promises about the future, saying that the current release is more stable and feature rich and the benefits in reducing the time to port future releases remains to be seen but that the Java implementation on Mac OS X is in a great position to move forward.
Dennison says that the new Java release is more closely aligned with Aqua and that, more generally, there is a tighter integration with Jaguar. For example, Java applications can take advantage of Quartz Extreme to get faster rendering for scrolling, faster window movement, and improved performance in transparency effects. As Quartz Extreme evolves, the performance of the Java GUI will improve as well. As another example, there is a better match between Java and Cocoa than there was between Java and the preemptive threading model of Carbon. For non-GUI applications, the Java threads have mapped to native Mach threads, but for GUI applications there has been a traditional mismatch between Java and Carbon. Much of the reduction in Apple's glue code has been eliminated because of this move from Carbon to Cocoa.
With Jaguar, Apple made a commitment to supporting the U.S. government's Section 508 Accessibility statute with its Universal Access features. These allow users to open up their system preferences and configure their Mac to take advantage of assistive technologies that help with seeing, hearing, and using the keyboard and/or mouse. The Apple Java team has built the Java Accessibility API on top of this Jaguar API. In addition, once you have the handles to the buttons and menus in a Java application necessary to enable the accessibility features, you can make those same handles available to the new AppleScript GUI Scripting. When you bring up a Java 1.4 application, you'll see the button hierarchies and so on, and can make calls into your Java application from AppleScript. In addition to making your Java applications AppleScriptable, this also provides a nice framework for doing GUI testing of your Java application.
Where does Java fit with all of Apple's developer APIs. A quick look at the base Mac OS X install shows support for developing in Perl, Python, PHP, Ruby, C, C++, Objective-C, and Java. The amount of developer tools that come standard on the platform makes Mac OS X a natural choice for a development platform. Dennison advises that Java continues to be the right choice if you are considering a cross-platform application. If you're developing solely for Mac OS X, Java may not be your language of choice.
According to Dennison, "The days of providing specific Java APIs for Mac technologies are gone." This means if you want to make calls into native APIs you are going to have to use JNI as JDirect is going away. Looking at Apple's approach in the area of accessibility, the standard Java APIs will be used to call into the appropriate native technologies. You can't expect to see Apple releases of JavaBeans for the Speech and Spelling frameworks as in the past. There is no reason, however, that these wrappers can't be produced by third parties and made available.
Daniel H. Steinberg is the editor for the new series of Mac Developer titles for the Pragmatic Programmers. He writes feature articles for Apple's ADC web site and is a regular contributor to Mac Devcenter. He has presented at Apple's Worldwide Developer Conference, MacWorld, MacHack and other Mac developer conferences.
Read more Java Programming on the Mac columns.
Return to the Mac DevCenter.
Copyright © 2009 O'Reilly Media, Inc.