Painless Java on mobile

Spotlight on: Codename One – converting Java to native mobile apps

Chris Mayer

We speak to one of the co-founders of a new startup aiming to allow Java to be used in cross-platform native mobile app development.

There’s no escaping the fact that the realms of Java and modern mobile development aren’t the best of bedfellows. For years now, writing iOS and Blackberry apps in Java out of the box has been an impossible task. Developers have been well within their rights to look elsewhere for a solution to their problem.

Shai Almog and Chen Fishbein felt the problems of multiplatform development firsthand at Sun while working on J2ME. Fishbein was the man behind Java ME’s Swing-inspired Lightweight User Interface Toolkit (LWUIT), that aimed to make it easier to develop interfaces for embedded devices. With Oracle being neither mobile or client oriented, solving the issues in-house just wasn’t an option in the end.

Hitting a proverbial brick wall, the duo began to think about how to tackle Java’s modern mobile frailties. Thus in 2012, they founded Codename One: a new Java SDK allowing developers to write native applications, with support for iOS, Android, Windows Phone and Blackberry.

It’s a long overdue idea for Java. Almog told us that “Java solutions were either expensive proprietary heavyweight solutions or academic experiments that didn’t provide any sense of WORA which is highly important to Java developers. As long time Java advocates and Swing fans we were confident that the community will embrace this approach.”

Despite still being in beta, Codename One’s multi-layer approach is a well thought-out one. Having reviewed over 100 competing products before launch, Almog believes that Codename One’s offering is a viable one, despite the cross-platform competition.

“iOS is painful to program and Android is no panacea. Markets like Windows Phone/RIM get a lot of flack but by being in a small market your application can really stand out,” he says.

“I think that the pain faced by developers is very obvious and many want to solve it […] I think our product and its potential speak for themselves. I don’t think anyone has an offering remotely like ours.”

No adjustments need to be made as developers can simply install a plugin for their IDE (Eclipse or NetBeans currently) and get coding as normal. The built application is then sent as a compiler jar to Codename One’s cloud servers, where it is translated to the appropriate device’s language.

For iOS, the code is converted to C (with an Objective C porting layer) and Xcode is used to compile the app. For Android, Codename One compiled to DEX APK whilst for RIM and J2ME, the bytecode is adapted slightly with J2SE classes. So the WORA motto remains strong in Codename One, their software making it possible to invoke native code across the board.

Almog explains that if you’re a Java developer with a penchant for Swing, things should be quite easy to pick up, and assures us that their API layer “includes pretty much everything you would expect from a modern day mobile OS”.

“Since the API sits on top of a relatively narrow porting layer it is remarkably portable and most of the logic for the differences between the platforms is abstracted and shifted up into the Java layer,” says Almog.

“This effectively means that we can reproduce the iPhone/iPad feel on the desktop and within our tools. So using a port to Java SE we provide visual tools and a simulator platform that allows you to develop for all platforms without requiring that you install the full toolchain of the platform.”

There are some Java features that need to be adapted. For example, and Java’s File API’s don’t work well for mobile devices, so to perform networking or file system operations you should use our API’s,” Almog adds.

So where next for the plucky startup? JavaOne is on the immediate horizon, but Almog reveals there are many features in the works. With many solutions for cross-platform app development emerging, such as Phonegap and Titanium, it’s about time Java got a helping hand with mobile development.

Inline Feedbacks
View all comments