Google Translates Java to Objective-C With J2ObjC Tool

By Darryl K. Taft  |  Posted 2012-09-18 Print this article Print

Google's new open-source J2ObjC tool translates Java to Objective-C so Java developers can more easily build apps for the iPhone and iPad.

Google has announced the release of J2ObjC, an open-source command-line tool that translates Java code to Objective-C for the iOS platform so that Java developers can more easily build apps for the iPhone and iPad.

The goal of the J2ObjC tool is to enable developers 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, the Google Web Toolkit) and iOS, said Google engineer Tom Ball in a recent post on the Google Open Source Blog.

"J2ObjC enables Java code to be part of an iOS application's build, as no editing of the generated files is necessary," Ball said. "J2ObjC is not a Java emulator, but instead converts Java classes to Objective-C classes that directly use the iOS Foundation Framework."

The new Google tool supports the full Java 6 language and most of its runtime features that are required by client-side application developers, including exceptions, inner and anonymous classes, generic types, threads and reflection. JUnit test translation and execution is also supported. And J2ObjC can be used with most build tools, including Xcode and Make, Ball said.

According to the J2ObjC project page, the tool is currently between alpha and beta quality. However, several Google projects rely on it, though when new projects first start working with it they usually find new bugs to be fixed, Google said. As nearly every Java developer has a slightly different way of using Java, the tool has not translated all possible paths yet. It is released as J2ObjC version 0.5. Developers must use the tool on a Mac OS X system, with Xcode 4 or higher, Java for OS X and Apache Maven.

J2ObjC does not provide any sort of platform-independent UI toolkit, nor are there any plans to do so in the future, Google said. iOS UI code needs to be written in Objective-C or Objective-C++ using Apple's iOS SDK, just as Android UIs need to be written using Android's API and Web app UIs using GWT or other tools.

With a debate raging over whether to develop native, Web or hybrid apps for mobile platforms, Google's J2ObjC tool gives developers another choice for building apps for the popular iOS platform. Facebook CEO Mark Zuckerberg recently noted that one of Facebook's biggest strategic mistakes was to base its mobile app development strategy on HTML5 rather than going native.

Nat Friedman, CEO of Xamarin, a maker of tools for creating fully native apps with device-specific experiences, said, "Two years ago you might choose to do an iOS app as a first choice because the iPhone was the leading platform, but now with Android there's a challenge to that. And developers need tools to support building apps for these platforms." Xamarin's tools do that for C# developers, and now Java developers can use Google's J2ObjC.

Darryl K. Taft covers the development tools and developer-related issues beat from his office in Baltimore. He has more than 10 years of experience in the business and is always looking for the next scoop. Taft is a member of the Association for Computing Machinery (ACM) and was named 'one of the most active middleware reporters in the world' by The Middleware Co. He also has his own card in the 'Who's Who in Enterprise Java' deck.

Submit a Comment

Loading Comments...
Manage your Newsletters: Login   Register My Newsletters

Rocket Fuel