Google Open Sources Java To Objective-C Translator
Written by Mike James   
Monday, 17 September 2012

Why would anyone want to translate Java to Objective-C? Because Java is the language of Android and Objective-C is the language of iOS.

This also explains why Google is behind the project, or does it? The more you think about it, the less it makes sense.

j2ObjC is a Java source translator to Objective-C. Notice that this isn't a cross compiler but a source code translator. Given that Java is an object-oriented language,and so is Objective-C, and both are block-structured, C-like languages, this doesn't sound so hard. The real problem isn't in the syntax, but in system calls and idioms.

 

j2objcbanner

 

The intention of j2ObjC is to allow Java to be part of an iOS application build. The Google Open Source Blog puts it like this:

"j2ObjC enables Java code to be part of an iOS application's build, as no editing of the generated files is necessary. The goal is to write an application's non-UI code (such as data access, or application logic) in Java, which can then be shared by Android apps, web apps (using GWT), and iOS."

It works by converting Java classes into Objective-C classes that use the iOS Foundation Framework. It claims to support most of Java 6 including exceptions, generics and threads. The project page describes it as between alpha and beta quality and assigns it an inital version number of 0.5.

It also includes the telling remark:

"Several Google projects rely on it, but when new projects first start working with it, they usually find new bugs to be fixed. Apparently every Java developer has a slightly different way of using Java, and the tool hasn't translated all possible paths yet."

This is a reflection of the fact that the translator is not converting one precise grammar to another. Also, there are a lot of untidy details to deal with the exact semantics of the code in both languages. Put simply, translating between high level languages is often harder than compiling to machine code.

j2objc is limited in its usefulness because it doesn't do the hardest part of the conversion job - converting the UI code. Google says that there are no plans to provide any sort of UI toolkit and the translator is targeted at converting backend code such as file downloaders and similar.

To run the whole thing you need a Mac running OSX with Java installed and Xcode. The translation can be made automatic using a build tool.

Google claims to need the tool for internal projects - I wonder what they could be?

 j2objcicon

 

More Information

j2objc project page

Related Articles

Objective-C Overtakes C++ in TIOBE Index

Sams Teach Yourself Objective-C in 24 Hours

The Top Languages of 2011

 

espbook

 

Comments




or email your comment to: comments@i-programmer.info

 

To be informed about new articles on I Programmer, install the I Programmer Toolbar, subscribe to the RSS feed, follow us on, Twitter, Facebook, Google+ or Linkedin,  or sign up for our weekly newsletter.

 

Banner


Flutter Forked As Flock
05/11/2024

One of developers who worked on the Flutter team at Google has created an open-source form of the framework. Matt Carroll says Flock will be "Flutter+", will remain constantly up to date with Flutter, [ ... ]



OpenAI Library For .NET Exits Beta
19/11/2024

A few months ago the OpenAI .NET library was released as a beta. It has now reached version 2.0.0 and the time has come to leave beta and, with a few amendments enter production readiness.


More News

Last Updated ( Monday, 17 September 2012 )