PATH  Documentation > Cocoa > Using the Java Bridge


Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous | Next | PDF

Using the Java Bridge

Using Java from Objective-C

In Objective-C, you can use Java classes and interfaces as if they were Objective-C classes and protocols.

To reference class objects, you must use the function NSClassFromString() , since the Objective-C compiler can't generate static references to bridged Java classes. For example, to instantiate an object from the AJavaClass class, you would write code such as the following:

MyJavaClass = NSClassFromString(@"java.util.AJavaClass");
MyJavaObj = [[MyJavaClass alloc] init];

You can instantiate Java classes from Objective-C and see them as if they were pure Objective-C objects. You can also pass Objective-C objects as parameters to Java methods.

To invoke a Java method from Objective-C:

Exceptions raised within the Java code are caught and transformed into NSExceptions, which can then be handled by your code on the Objective-C side.


Previous | Next | PDF
\xA9 1998 Apple Computer, Inc.