Wednesday, 21 January 2009

Applet Jazz

Remember the early days of Java? Remember how the "write once, run anywhere" used to include running on a user's desktop, in the user's browser, until the big bust-up between Sun and Microsoft put a stop to all that? Before AJAX came along, applets used to be the coolest thing on the block at least as far as building webpages that looked a bit special. After the split, though, that all went away. "No-one wants applets" has been the refrain for several years now. Even Sun put applet development on the back burner, while concentrating on server-side Java with a bit of Swing on the side. There has been no real development of applet support since about 2001.

Well, all that may be about to change. With Java FX, Sun is aiming to product a platform for advanced graphics to compete with Flash and Microsoft's Silverlight. One thing that they are keeping rather quiet about is the delivery vehicle for an application written in this new language. It's applet technology. When you build a fancy display tool in Java FX, it's compiled and built into an applet. When you include it in a web page, your user must have Java installed before it will run. The big hope is that this won't put too many people off. After all, Flash sites require their users to install a browser plug-in, and Java won't be any different. Sun are clearly aware of the problem, and the latest version of Java includes various new features to make this installation process faster and more reliable. The question is, will this be enough? Is the installation process reliable enough, and does the platform offer enough features, to tempt web developers into using it?

For the installation process, I simply don't know whether most users will find it acceptable. All we can do is to assume that Sun will do enough, or have done enough, to convince developers that it's going to work. Taking that as a given, let's look at some other problem areas that my recent experience in building an applet has shown up:
  1. my applet had to be part of a very dynamic web page which used a lot of Javascript. In particular, some data had to be shown as overlays. This a very common Web 2.0 technique, but it causes problems, because some browsers will not display ordinary HTML elements over an applet. In many cases an IFRAME will do the trick, but not all. We had to resort to some browser-specific Javascript shenanigans to get it to work properly in various browsers, which is something we normally try very hard to avoid.
  2. the applet does graphics its own way, without using HTML and CSS. In some ways this is a good thing; if applets can't do more than HTML and CSS, what's the point? The issue here is that we've built up a lot of expertise in working with these tools. A designer produces a static picture in Photoshop, and we know how to convert that into a dynamic web page with styling that can adapt as the content changes. If we do that for most of the pages on a site, and we want to create an applet that has a similar visual style, then we have to re-implement the look in a completely different way. When it gets a re-design, we can't simply change a few stylesheets; the applet has to be re-programmed. I haven't got a good answer is to this one, but it clearly needs to be addressed. The web has moved on since applets were first thought of, but applets haven't moved with it.
  3. on a related issue, the support for displaying HTML inside an applet is very poor. It uses an old version of HTML, and doesn't seem to support CSS at all. This is simply not acceptable.
  4. in Flash, you can download and use a font without needing to install it in the user's system. That's a really significant feature. In Java, you can offer the user the chance to install a font, but that creates an annoying dialog, and if they aren't an administrator on the machine, they can't do it anyway! If Flash can do this, why can't Java?
I dearly wish that Sun would fix the problems, and make applets into a viable technology again. I've tried programming in Javascript, and I hate it! It's OK for simple things, but as soon as it gets at all complicated, it becomes very difficult to write and debug. Wouldn't it be great to be able to program Web 2.1 in Java?

No comments: