One Solution To Code Them All?
Running Java on iOS is less the holy grail prospect that it once was. One project carving serious in-roads into the write-once-run-on-all-the-hip-devices dream is Codename One, which offers a unique cross-platform solution for coders. We spoke to co-founders Chen Fishbein and Shai Almog at JavaOne, who were also joined by Steve Hannah – an enthusiastic user who’d dipped his toe into Codename One, and ended up becoming fully immersed.
What’s the central work of CodenameOne?
Shai: At CodenameOne, we essentially allow Java developers to write their applications once, and have them work in iOS, Android, Windows phone, etc. It’s an open source project that started at Sun Microsystems back in 2006, and eventually we took that open source project and turned it into what is CodenameOne today.
The way it works is, when you write an application, you write it in Java using a Swing-like API and optional GUI builder. You can debug it using a simulator – we support NetBeans, Eclipse and IDEA plugins, then when you want to actually debug the application, you can right-click the project, say I want, for instance, a native iOS build, the JAR file – the binary – is sent to our build cloud, where the binary is converted to a native application by going to C source code, compiled using X code andsigned using X code. Now, this roundabout way is important because Apple changes things practically all the time, and this is futureproof in terms of Apple because it’s as though you coded everything by hand. This way, you can get an application that will probably always work on iOS devices- and the same goes for all the other platforms that we support as well.
Given that you started in 2006, this actually predates the iPhone…
Shai: Yes, back then the original codebase was created for a JQuery based project essentially, and we quickly turned it into an Android and RIM project, then as iOS came along, we tried to make these devices work more like iOS and behave like that in the modern way of looking at UIs. Unfortunately, innovation in a large company is very difficult, and getting things out in terms of all the management layers – it’s just not designed for that. Innovation always carries a risk within it, that only startups can properly take. We had no choice because we firmly believed in the technology and we had to leave and do this.
Steve, how did you get involved with CodenameOne?
Well, I’m a department of one at Simon Fraser University, and I have a background in Java, so about two years, I went looking for a solution to do Java on the iPhone. I was actually looking for a way to just have one codebase on the iOS, but Java was a bonus, and CodenameOne is the only company that allowed me to have one codebase through and though. There were solutions that allowed me to share business logic, and there were solutions that would allow me to have Java as part of it, and then an HTML UI – but the HTML for the UI would only get me so far before my users would be complaining about some sort of performance issues in usability. So when I hit CodenameOne, it was a perfect fit.
There are other similar solutions to CodenameOne out there – and getting Java on iOS has been talked about a lot at this year’s event. What makes you different from people like RoboVM?
Well, RoboVM is Java for iOS – we’re Java for ‘write once, run anywhere.’ We have a very different goal, on a very basic level. RoboVM works with native code, you need a Mac, you need to understand the view controller in iOS, and write natively for that. It’s really a competitor to X-Code. So rather than write in Objective C, you can instead use RoboVM and write your code that way. They also support a very nice gaming library called Lib-GDX, which some people use for Android. So if you’re trying to write games, RoboVM is very good for that sort of thing.
We’re trying to abstract that, to go to a higher level. In that regard, we target application developers, rather than game developers, and corporate and enterprises, and that market. People who would rather use Swing than platform native tools, for example. And in that way, we allow developers to write applications that run also on Android, which is still 85% of the devices on the market, and on Windows Phone as it starts growing and becoming a more important platform, and our applications even run on the desktop if you choose to do so.
We don’t highlight that, because we’re still a mobile development tool, but you can do pretty much all platforms and the solution is more wide. We’re also based on the cloud, so for us you don’t need a Mac, or any of those other aspects of software development.
How would you say performance on iOS compares when using your technology to developed as opposed to the more traditional options?
Performance wise, Steve actually surprised us when he started benchmarking. We didn’t even have time to do that in the beginning. And when we got something that felt right, we said, “Well, that’s good enough.” But when Steve did his tests, he surprised us that things like Method Invocation were actually faster than Objective C message dispatch. And the thing is, Objective C itself, which is the language used by default in iOS and Swift, isn’t that much faster in that regard, uses messages not Method, and that’s much slower because they are bound dynamically. We’re actually faster than Objective C in that specific benchmark. Obviously, performance is a much wider subject than just this. You can read my article ‘Beating the ARC’ where we beat the performance of the Reference Counting Solution in iOS, and how we do that.
In terms of graphics, we actually contracted Steve for some work on that aspect, and he did some amazing work on our graphics pipeline, which is based on Open GL. So it’s the same performance as a game would have in terms of speed.
Steve: I was really surprised with the benchmarks too, because I always had the common misconception that Ahead of Compilation means faster…and I was really surprised with the results that I got with CodenameOne’s solution that it actually doesn’t mean anything in terms of performance.
Where are you guys at with the software? What’s on the roadmap ahead?
We’re on CodenameOne 2.0 right now – we wanted to release CodenameOne 3.0 for JavaOne, but we procrastinated and didn’t get that done in time – it’s going to be out soon though. It’s going to have a completely new VM for iOS which includes a faster Garbage Collector that doesn’t stall and doesn’t synchronise, it includes the new graphics capabilities that are comparable in ability to JavaFX in many aspects, and a lot of other cool new features.