Google Open Sources Java To Objective-C Translator
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.




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?



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




blog comments powered by Disqus


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.



Facebook Closes M, Its Virtual Assistant

Facebook is shutting down M, its virtual assistant that relies on help from humans to handle users' questions and requests. Launched in limited beta almost two and a half years ago, it was only ever o [ ... ]

Describe It And AI Will Draw It For You

Neural Networks do seem to be able to keep on impressing us with their ability to do different tasks better than we thought possible. The latest in a trio of networks from Microsoft has the ability to [ ... ]

More News

Last Updated ( Monday, 17 September 2012 )

RSS feed of news items only
I Programmer News
Copyright © 2018 All Rights Reserved.
Joomla! is Free Software released under the GNU/GPL License.