Mobile AJAX and Java ME: Closer Than You Think

I’ve submitted a follow-up article to my introductory SOA and Java ME article. The new article focuses on asynchronous calls, and I’ll post an announcement here when it goes live. However, I wanted to talk further about one of the claims I made in the article on how Java ME and AJAX are related.

What is AJAX?

According to the seminal article about AJAX (I wish things I wrote were referred to as “seminal”, it sounds so impressive), the term “AJAX” stands for asynchronous JavaScript and XML. The idea is fairly simple. Instead of building a web application using the traditional “dumb client” approach (all logic on the server), move as much logic as you can to the browser (writing it in JavaScript) and communicate with the server asynchronously (in the background), receiving data in XML or some other JavaScript-friendly (like JSON) format.

The benefits of AJAX are threefold. First, it reduces the server’s workload — it’s not spending most of its time generating pages in response to changes on the client. Second, applications become much more responsive due to the local logic — no roundtrips to the server and back in order to expand a tree node, for example. Third, there’s nothing to install on the client — the user just starts up a browser and navigates to the right URL; as long as they have Internet access, they’re in.

Oh Yeah? Try Mobile App Development!

One of the things I’ve always found funny about the AJAX programming metaphor is that many developers think it’s new technology. The truth is that mobile application developers have long faced the same underlying issues. It’s kind of inevitable, really: when the network is slow or unavailable, you generally have two choices for building network-enabled (as opposed to completely standalone) applications. The first choice is to replicate the entire application, or its equivalent, on the device. You have a database application running against a big database server? Port it to the mobile platform and have it run against a local database, then have the local database synchronize itself with the database server whenever possible. (Advertisement: SQL Anywhere has two different mobile database engines that can sync to all the big name database servers.)

The second choice is to use an asynchronous model. Talk to the server using a queuing methodology. Send out the requests, but don’t wait for them to come back. Let the user continue to work. When the responses do arrive, process them. There are many ways to do this. (Advertisement: QAnywhere is one way.)

Mobile AJAX?

You might think that AJAX is the perfect technology for building cellphone-based applications. Especially with the powerful mid-range and high-end phones now available. And you might be right, except of course that most mobile browsers don’t support the functionality needed to run AJAX applications.

I say “most” because there is actually a “mobile AJAX” product on the market right now called M-Business Anywhere that lets you develop web applications with JavaScript-based local logic on mobile devices — it certainly sounds AJAXish, doesn’t it? In fact, it’s the basis for the AvantGo service, which mobilizes web content for free. But M-Business Anywhere can go further than that and mobilize enterprise web applications. No, it’s not strictly-speaking AJAX because there’s no XMLHttpRequest object, but it’s nevertheless an async development model. I know, because write now I’m developing the BlackBerry client for the service.

AJAX = Asynchronous Java and XML?

But our focus here is Java, and Java ME specifically. How do AJAX and Java ME relate to each other?

Not directly, it would seem, unless you change your definition of AJAX. Maybe for Java ME developers “AJAX” really stands for asynchronous Java and XML. It’s what we do today to get our apps working well: background communication over HTTP using simple data exchange protocols, with local logic for the user interface.

Maybe we’re more bleeding edge than we thought!

Eric Giguere is a software developer at Sybase iAnywhere who has published extensively about Java ME programming. This entry is from his J2ME Programming Guide.

Technorati Tags: , , , , ,

Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages.
  • blinkbits
  • BlinkList
  • blogmarks
  • co.mments
  • connotea
  • del.icio.us
  • De.lirio.us
  • digg
  • Fark
  • feedmelinks
  • Furl
  • LinkaGoGo
  • Ma.gnolia
  • NewsVine
  • Netvouz
  • RawSugar
  • Reddit
  • scuttle
  • Shadows
  • Simpy
  • Smarking
  • Spurl
  • TailRank
  • Wists
  • YahooMyWeb

Leave a Reply