In association with heise online

14 September 2012, 15:08

Google releases Java to Objective C translator

  • Twitter
  • Facebook
  • submit to slashdot
  • StumbleUpon
  • submit to reddit

Java/iOS icon Google has released J2ObjC, a translator that converts Java code to Objective C for iPhone and iPad. The idea behind J2ObjC is to allow developers to share non-UI code more easily between Android devices or server-based GWT applications that use Java, and Apple's iOS devices which use Objective C. The translator can handle Java 6 code happily though it is described as "currently between alpha and beta quality".

The translation process, currently, involves the conversion of java.lang.Object to NSObject, boolean to BOOL, byte to char, instance variables become properties, inner and anonymous classes are converted to specifically named outer classes, interfaces become protocols and JUnit tests are converted into a JUnit-styled versions of tests. A mapping file then defines the conversion of Java methods to iOS Foundation methods. The process is documented in the Design Notes and, for example, would convert

int getLength(List<String> list, int index) {
return list.get(index).length();


- (int)getLengthWIthJavaUtilList:(JavaUtilList *)list withInt:index {
return [(NSString *) [list getWithInt:index] length];

As Java code is garbage collected, the translator also has to manage mapping that across. Developers can specify whether this uses reference counting (the default), garbage collection with libgc (with --use-gc) or automatic resource counting (ARC, --use-arc) at translation time. The developers hope to make ARC the default in the future. They are not planning on developing any cross-platform UI, instead focusing on the translation of application logic and other non-UI elements.

The translator can be integrated into the XCode IDE's development workflow or with Maven and Make. The Apache 2.0 licensed J2ObjC is available from the project's Google Code site where documentation and guides on its usage are also available.


Print Version | Send by email | Permalink:

  • July's Community Calendar

The H Open

The H Security

The H Developer

The H Internet Toolkit