Cocoa and Java: Lots of Promise, But...
by James Duncan Davidson
Currently, the Mac Devcenter is running a series of articles by Mike Beam entitled Programming with Cocoa. This series is geared towards looking at Mac OS X's Cocoa APIs as expressed in Objective-C. This is only natural given that Objective-C is the native language of Cocoa, but since I am approaching this weblog from the perspective of a Java coder, I've been experimenting with Cocoa's Java APIs.
There is a lot of general documentation on Cocoa at Apple's Cocoa Developer website. And the tutorial on how to get started using Cocoa in Java is a good start. It shows the power of Interface Builder and Cocoa, and yet is an easy read. I had the sample Temperature Converter up and running in no time. But, after that point, the remaining Java oriented documentation consists mainly of the Application Kit and Foundation API references. And worse, these references are incomplete ports of the Objective-C documents. For example, the following sentence comes from the Java application references for the NSEvent class:
"NSWindow and NSApplication define the method nextEventMatchingMask:untilDate:inMode:dequeue:, which allows an object to retrieve events of specific types."
The above makes very little sense to a Java programmer unless they have some experience with Objective-C message naming conventions. Somebody that had never seen Objective-C might translate the above to a Java-ish method of nextEventMatchingTask(untilDate, dequeue) and looking in the documentation for NSApplication, there is no exact method of this signature. Instead, there is a method signature of nextEventMatching(int mask, NSDate expiration, String mode, boolean flag). At this rate, I'd rather just have sparse Javadoc generated documentation.
Don't get me wrong, after my initial foray into Cocoa, I'm impressed. Interface Builder is a dream to work with and the performance of Java driving the native Cocoa widget set is impressive. There is lots of promise here, but right now the documentation is not geared towards Java programmers. In order to make heads or tails of it, you end up learning quite a bit of the Objective-C language. There is nothing wrong with knowing another language, and I've found Objective-C to be fascinating (I'll have more on this subject in the coming weeks). However, a lot of work remains to be done before typical Java programmers will be able to easily use the Cocoa APIs.