Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Cocoa and Java



When you build a Cocoa-Java app, your .java files are compiled into .class files, and put into a .jar file in "NSJavaRoot", defined in your project. The default location is Contents/Resources/Java.

If you build your Cocoa-Java app, and use the "jar" tool from the Terminal like this, you can see what's in your .jar archive. It should be what you expect:

> jar tvf Aquataxx.app/Contents/Resources/Java/Aquataxx.jar

0 Thu Oct 31 16:07:26 CST 2002 META-INF/
67 Thu Oct 31 16:07:26 CST 2002 META-INF/MANIFEST.MF
1350 Thu Oct 31 16:07:14 CST 2002 AtaxxApplication.class
736 Thu Oct 31 16:07:14 CST 2002 AtaxxController$1.class
3294 Thu Oct 31 16:07:14 CST 2002 AtaxxController$RosterDataSource.class
36445 Thu Oct 31 16:07:14 CST 2002 AtaxxController.class
729 Thu Oct 31 16:07:14 CST 2002 AtaxxGame$Move.class
10423 Thu Oct 31 16:07:14 CST 2002 AtaxxGame.class
1063 Thu Oct 31 16:07:14 CST 2002 AtaxxNode$RosterThread.class
11845 Thu Oct 31 16:07:14 CST 2002 AtaxxNode.class
1817 Thu Oct 31 16:07:14 CST 2002 AtaxxView$MoverThread.class
20153 Thu Oct 31 16:07:14 CST 2002 AtaxxView.class
0 Thu Oct 31 16:07:12 CST 2002 com/
0 Thu Oct 31 16:07:12 CST 2002 com/buzzlabs/
0 Thu Oct 31 16:07:12 CST 2002 com/buzzlabs/net/
5777 Thu Oct 31 16:07:12 CST 2002 com/buzzlabs/net/Connection.class
3519 Thu Oct 31 16:07:12 CST 2002 com/buzzlabs/net/Listener.class
0 Thu Oct 31 16:07:12 CST 2002 com/buzzlabs/util/
1018 Thu Oct 31 16:07:12 CST 2002 com/buzzlabs/util/DeferredTask.class
2519 Thu Oct 31 16:07:12 CST 2002 com/buzzlabs/util/Message.class
215 Thu Oct 31 16:07:12 CST 2002 com/buzzlabs/util/MessageHandler.class
287 Thu Oct 31 16:07:12 CST 2002 com/buzzlabs/util/Messenger.class
1501 Thu Oct 31 16:07:12 CST 2002 com/buzzlabs/util/MessengerImpl.class

A Java VM is created when you launch your application. Your application runs both in Objective-C land (with a native Cocoa interface), and in the VM for your code. There is a Java-Objective-C bridge that allows you to call "bridged" Objective-C classes from Java, and Java classes from Objective-C. You can freely mix Java and Objective-C. The bridged Cocoa-Java classes are in the com.apple.cocoa.* hierarchy.

You can achieve very nice performance with Cocoa-Java. It'd be great if in the future, Java byte codes or source would be compiled into native code, but it's not necessary, as the Hotspot JIT seems to do a good job of compiling your stuff at runtime. The overhead of the JVM might be an issue -- it likes a good deal of memory, but you might win from having access to the vast number of libraries available to Java developers.

There are some classes that are not available from Java land. I assume you could use them via JNI if you wanted to. It would be very nice if Apple would keep Cocoa-Java in parity with new developments in Cocoa (Objective-C), and I do hope that Apple continues to support Cocoa-Java, as it's a really great way to write Mac OS X applications.

I don't think that Java is any less a "real language" than Objective-C, really. It takes longer to launch your app as the VM has to start up, and performance will not be as great as Objective-C, but there are many areas where you won't notice much a difference.

I believe that Cocoa uses QuickTime for reading non-TIFF image formats. There's a specific bug with reading GIF images from a Cocoa-Java application; I avoid using GIFs in Aquataxx; I use compressed TIFF images.

You can check out the latest version of Aquataxx here: http://www.buzzlabs.com/aquataxx/ -- tell me if you can tell it's Java, without looking at the app package internals or the "top" readouts. It's hard to do.

Steve
_______________________________________________
java-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/java-dev
Be sure to read the FAQ http://developer.apple.com/java/faq/ before posting
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.