What is the point of Java on the iPhone?

March 12th, 2008
Filed under: Apple, General, iPhone, Java, Mac OS X | Huibert @ 9:20 pm

java_iphone-thumb.gifI love Java. A large part of my success as a software developer over the last decade is due to the fact that I was an early Java adopter. Java also allowed me to grow professionally and become a Software IT Architect at IBM. Over the years I have written many J2EE web apps, some J2SE applications and even one Java2ME program for a Sony-Ericsson handset. The fact is that I am totally convinced by the many benefits of Java and I do not feel attracted by any other language to write enterprise web applications. But seriously, Java for the iPhone? Why?

On the server, J2EE is extremely appealing because it is an open, scalable, secure technology that allows developers to create complex solutions. If you plan to integrate all kind of legacy systems or develop true robust distributed systems Java simply has no competition.

On the desktop, the situation is quite different. Sun Microsystems tried to create a platform that would allow developers to create applications that would work on any OS. Their first attempt at providing a common GUI was the AWT. It was a complete failure because it only allowed to use controls common to all existing platforms. Complex controls such as trees or tables could not be used because even if they existed on Windows or the Mac, they were not available on other OSes such as QNX. The second attempt, an API usually known as Swing (or JFC) tried to solve the problem by avoiding native widgets altogether. Instead, each component was drawn in Java, bypassing the OS. This move allowed Sun to support complex controls on any OS. However, the first release of Swing was painfully slow and a memory hog. As a result, most developers have avoided the technology despite Sun’s efforts to improve it in subsequent releases. The problem is that every time the Look and Feel of an OS is updated, Swing needs to be updated also, to ensure that widgets are drawn properly. IBM proposed a better solution, called SWT, used in Eclipse and many other Java applications. Instead of hand drawing all controls, SWT uses native controls when available and draws them manually as a last resort. The result is a more efficient API that produces much better results. Even so, users normally can quickly spot Java desktop apps because they simply do not look native. This is specially true on the Mac. While PC users seem to have no problem at all using Java applications such as Azureus, Mac users seem to prefer non Java alternatives such as XTorrent or Transmission. To make a long story short, those who designed the Java strategy for fat clients assumed that all GUI were similar and that any differences were merely cosmetic. It was a terrible assumption that was made well before Apple migrated from OS 9 to OS X (which makes heavy use of transparency and animations) by people who could not envision how technologies such as hardware accelerated graphics would impact GUIs. The result is that very few still consider Java as a viable option for creating desktop applications.

On a phone, the situation is even worse. Developers don’t really know what to expect from a Java capable phone. There isn’t much standardization and capabilities vary significantly from one phone to another. The main benefit of Java2ME on a cell phone is that it makes migrating applications from one cell phone to another relatively easy. This is specially true for mobile games that do not require a standard user interface and where all the display is handled by Open GL.

The iPhone is a device that lies somewhere between a computer and a phone. It has an amazing user interface that users expect applications to fully embrace. Java currently does not offer any solutions to work effectively with that aspect of the device. However, Java could still prove useful to help quickly migrate all those games written for other handsets to the iPhone. Is this important for Apple and iPhone customers? I doubt it. With over 100,000 SDKs downloaded in just over four days, it seems that the iPhone will not lack native software (including games). The announcement made by Sun that it plans to make Java available for the iPhone is mainly targeted at existing J2ME developers. The company run by Jonathan Schwartz wants to open a new market for their software development partners to prove the value of J2ME by making it easy to sell old content on a new platform.

Until now, only large companies could negotiate with telcos to get their content on the carrier’s phones. The margins were razor thin and to make any money you needed to get your content on millions of phones. Supporting multiple brands of handsets was a necessity and in that context, Java was a blessing. The announced App Store is leveling the playing field. Now everyone can sell mobile apps. With 70% of the price of the software going straight to the developer, it makes sense to develop applications specifically for the iPhone.

On March 6th, Apple invited mostly large companies to show the software they were working on at the iPhone software roadmap event. However, you will see that by late June, when Apple releases version 2.0 of the iPhone firmware, most of the applications available through the App Store will come from passionate independent developers that will try to get out the most out of the device, not companies trying to obtain incremental revenue from something written years ago. In fact I predict that many large companies specialized in developing software for mobile phones will find it difficult, at least at the beginning, to compete against many of the enthusiasts who will create innovative solutions at home during their spare time.

I abandoned Java on the desktop for Objective-C years ago because Cocoa allowed me to get the most out of the Macintosh platform. The same applies to the iPhone. Objective-C is similar to Java in many ways. What makes the difference is Cocoa touch which is a great development framework and allows to get to the guts of the iPhone without compromises. That is why I personally don’t care if Sun releases a Java SDK for the iPhone or not. I am quite sure most of those 100,000 developers who have downloaded the SDK agree with me.

9 Responses to “What is the point of Java on the iPhone?”

  1. Java on the iPhone « Ramblebot Says:

    […] on the iPhone Posted by Chris Gervais under iPhone | Tags: iphone java who-cares |   What’s the point of Java on the iPhone? Great question. I’d put the question about Flash in the same category. The category is: […]

  2. Steve Moore Says:

    Great post. am I right that the Java side of development is more engineering focused than customer focused? Customer’s don’t care how easy it is to move an application from one device to another, they just want it to work well and fit everything else on their system.

  3. Huibert Says:

    Steve, I am not sure that Sun would agree with you. They would argue that Java was designed to give customers choice over their favorite OS or handset. In practice though, you are right because Sun had to compromise too much in order to achieve portability on the client side.

    On the server side the story is quite different. Java customers have benefitted from increased competition and innovation among hardware and software manufacturers.

  4. Umberto Says:

    A modern Java VM is an extremely fast environment based on a very advanced set of libraries that handle everything from massive parallelism to hardware abstraction very well. It’s probably faster than the Objective-C runtime on which the MacOS X is based. Objective-C has the worst of both worlds– static compilation with dynamic linking. Since Java is dynamically compiled, it has runtime information available to the optimizer which means it can optimize the wazoo out of the code and cache the optimized version. Objective-C’s extreme bent towards dynamicism means almost nothing can be inlined and everything turns into these huge stack calls in assembler. It was a great choice for the late 80’s, but the state of the art has moved way beyond it by now.

    The problem with a modern JDK’s perceived performance is not so much its speed, but its size. Since they didn’t break it down into little pieces that could be loaded individually, it takes potentially dozens of MB just to start executing line 1, so it takes even the tiniest applet many seconds to get going while flash starts almost immediately. Sun is fixing that in JDK6u10, due out in a few months. Java applets will start just as fast as Flash. And since Java is a very deep, well-architected system (unlike Flash) it will make a very compelling case for developers.

    It’s no coincidence that Java is everywhere from your Blu-Ray player to your set-top box to the servers running a website. The only place Java HASN’T gained traction is in front of users eyes. Personally I think that’s because Swing made some bad choices and Sun hasn’t prioritized the desktop.

    Besides, the chipset Apple chose for the iPhone/Touch has some native support for Java. It’s likely that Java will run faster on it than anything else you’ve tried.

  5. Desenvolvedor: ‘Java no iPhone? Pra quê?’ | AppleMania.info Says:

    […] detalhes no artigo completo de Aalbers. No momento da finalização deste artigo nosso iTunes tocava: Hans Zimmer & Lisa […]

  6. Huibert Says:

    Umberto, if you read my post carefully, you will see that I never say that Objective-C is superior as a language to Java. If I did I would be calling for someone to write an Objective-C app server and I don’t. The problem is that Java doesn’t offer a good way to write user interfaces that actually take advantage of the native GUI. That may not be very important on Linux or Solaris but it matters on the iPhone. Sure, I could use JNI to make native calls to the OS but that defeats most of the benefits of using Java.

    I still love Java and think it is a great platform for the enterprise, I just don’t want it on my iPhone to get the full UI experience Apple designed.

  7. thunk Says:

    @Umberto

    On the contrary, the state of the art is moving toward more dynamic linkage due to the increased flexibility of the resulting software.

    Java has some excellent attributes, but there are some things for which it is not well suited. In full-sized systems, making low latency, high performance applications (games, analytics, engineering) is almost never done with Java. In a constrained system, performance issues are magnified, and Java is not going to make for the best solution in an even wider scope of applications.

    The reason, I think, is partly architecture, and partly the difficulty of making complete type-safety as efficient as partial type-safety: Objective-C can outperform Java in the all-important inner loop routines because Java requires more checks for its complete type-safety, and also the bottom-most parts of any Objective-C application can very easily be written in C or C++. Some other architectural issues were identified and addressed by Microsoft in its take on Java, with some gains in performance, but type-safety keeps these sorts of languages from being top performers in many applications.

  8. Jorge Chamorro Says:

    The truth is that it’s not in Apple’s plans to promote any propietary web technology. Flash, SilverLight and Java therefore do not fit in their plans… As somebody elsewhere has already pointed out, the functionality incorporated in the last version of WebKit shows their standars-compliant non-propietary vision of how RIAs and/or the Web 2.0 should be deployed instead. A (silent) war is taking place on the internet front, altough most people seem not to be aware of it.

  9. Huibert Says:

    Jorge, you are right about Flash and Silverlight but Java can hardly be called propietary. What you probably mean is that Apple is betting on HTML5 for the presentation layer and is making no bets on the server side. If that was the case, you are absolutely right. However, in order to succeed, Apple needs to quickly grow Safari’s market share so that no business user can ignore that market and therefore chooses not to adopt non-standard technologies such as Silverlight or Air. That reasoning is probably behind Apple’s recent decision to push Safari 3.1 to Windows iTunes users.

    Even so, there is a big Java market for web application developers and Apple has never been enthusiastic about that technology either. I am not really sure why. Apple could win many Java developers over by providing first class support for that programming language and they have clearly chosen not to do so by severely limiting their investment in that technology and by not participating actively in other community objects such as Eclipse or J2EE. Despite that decision, many Java developers use the Mac as their development platform (myself included). However, better Java support could woo many Windows an Linux developers to the Mac platform.