This content is part of the Essential Guide: JavaOne 2014: Takeaways from Java's biggest conference
News Stay informed about the latest enterprise technology news and product updates.

Startup promises native Java across mobile platforms

Learn how startup company Codename One is promising native Java across mobile platforms.

At the JavaOne show in San Francisco, enterprise architects debated the merits of hybrid versus native deployment models for rolling out cross platform mobile applications. Native Java applications typically provide better performance. Hybrid approaches like Apache Cordova have lower development costs, since the same code can be leveraged across multiple platforms. An Israeli startup that emerged out of work at Sun before the Oracle acquisition, Codename One, has developed a novel architecture that allows a single Java codebase to be compiled natively across iOS, Android and Windows Phone platforms with a cloud-based service. We caught up with Codename One CEO Shai Almog, who explained how this works.

How do you run native Java on the iPhone?

Shai Almog: After the Java code has been written, the JAR file is sent to the cloud where we have Macs configured to generate iOS code. These grab the byte code, convert it to C and compile it using the latest version of Xcode for iOS. We do it this way to maintain future compatibility with updated versions of iOS. Apple often changes things, and this makes sure it just works. We do something similar for Windows Phone as well, where we translate the Java code into C#.

Can this be done in a way that allows enterprises the ability to maintain control of proprietary source code?

Shai AlmogShai Almog

Almog: We also make this capability available to be implemented [on premises] by the enterprise so they can still enjoy the benefits of compiling to the latest version of iOS, while keeping the source code safe within the enterprise.

How can this type of infrastructure ensure best practices for coding across different platforms?

Almog: We translate the Java code for the various platforms in such a way that it is compiled using a non-blocking garbage collector, and so that multiple threads do not block the current execution of the main UI thread. For native code compiled for iOS, this approach can even provide better performance than possible when writing directly in Xcode for some use cases. For example, a method call in Java can be translated into a function call in C. A message dispatch written in Objective-C for iOS requires more assembly functions that end up being slower in terms of application performance. Also, our new garbage collector is faster than the Automatic Reference Counting on iOS that is used for garbage collection functionality. Other use cases might be slower, but generally, the performance of this approach is comparable to native apps.

How does this kind of approach address accessing mobile platform functionality and UI elements that differ across iOS, Android and Windows Phone platforms?

Almog: There are edge cases where we might not provide access to native functionality. For these we provide the ability to access native interfaces that can be called from Java. This makes it possible to access functionality that is not exposed in the basic development kit. We also have translators defined for the mobile platforms that behave differently with Android, iOS and Windows so that the same code can provide different UI effects. This makes it easy to generate an overscroll effect that is different on iOS and across the different flavors of Android.

What are the benefits of compiling a single Java project for mobile platforms compared to hybrid approaches like Apache Cordova?

Almog: Cordova takes the worst of both worlds and combines the faults together perfectly. Our approach is more like Swing. We are trying to make it easy to write an application in Java and it just works seamlessly for building native applications. I think it is doable because our abstraction is similar to Swing and because of the use of API styles and theme painters.

Can this approach make it easier to integrate into back end enterprise services like databases and legacy applications?

Almog: We provide a Web service wizard that generates the server side code for deploying to J2EE and provides a parser for REST, XML and JSON. It also provides object capabilities for push, object storage and file storage in the cloud so that you can get started right away to build something useful. It also includes authentication support of OAuth.

Is the platform open source?

Almog:  Everything, including the plug-in for the IDE and simulator, is open source except for the build servers. Even the virtual machine for iOS is open source. The platform is free to get started on with a quota since we believe in building up the community to encourage better feedback. Over 15,000 developers have worked on the platform.

Dig Deeper on Application performance measurement and Java performance

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.