On CBS MoneyWatch: The perfect car for a teenager
BNET Business Network:
BNET
TechRepublic
ZDNet

May 27th, 2009

Google I/O: How do I code thee? Let me count the ways

Posted by Ed Burnette @ 8:01 pm

Categories: AJAX, Android, General, Google, IO2009, Programming, Web Browsers

Tags: Google Inc., I/O, Dalvik, Native Code, Dalvik App, Web apps/Ajax App, Android 1.5, Android Browser, NDK App, AJAX

Dan Morrill presented a great talk this morning on the 3 different ways to code for Android: Managed Code (Dalvik), Ajax, and Native Code. To demonstrate the different ways Dan decided to write the same app , a k-means clustering application, 3 different ways.

The first way is managed code. Dalvik is a virtual machine optimized for embedded devices. It’s designed to run fast without having to be compiled. Dalvik apps are backed where needed by system infrastructure in native code, for example OpenGL, Binder IPC, media, etc.. Dalvik is the richest form of app development on Android.

Web apps/Ajax apps are broken up into declarative layouts and code. JavaScript mutates the DOM to create UI effects. Recently the canvas tag allows JavaScript to do direct painting. Android 1.5 includes a browser based on WebKit + SquirrelFish. It uses WebKit v528.5, which is equivalent to Safari 4 beta, but due to a bug it reports as 3.1.2 in the user-agent string. The Android browser includes support for the canvas tag and the Google Gears plug-in (version 0.5.17.0 (with location).

Native Code is supported in a Native Development toolKit (NDK) which was recently added to the “Donut” branch in source control. NDK apps are launched as a Dalvik applications that load a dynamic library and then make calls into native code via JNI for heavy lifting. Native code is useful for things like physics simulations, efficient/fast loading of large-ish data files, speed-intensive lookups, and custom VMs like SCUMM.

Dan timed the various implementation to discover their strengths and weaknesses:

  • Dalvik: 18ms render, 1000ms calculate
  • Ajax: 334ms render, 698ms calculate
  • Native: 18ms render, 150ms calculate

He also demonstrated what he called “Amplified Ajax”, which is involved extending the Ajax DOM in an Android WebView with either the Dalvik or Native implementations.

During the talk Dan revealed some future directions for Dalvik and Ajax on Android. In the future the Android team is planning to enhance Dalvik by introducing:

  • Improved garbage collection
  • Just-in-Time compilation
  • Optimization in core libraries
  • Additional APIs like Bluetooth, P2P networking, and more

Ajax coders on Android can look forward to:

  • Improved HTML5 implementation
  • Faster JavaScript virtual machines

Ed BurnetteEd Burnette is a professional developer and author of several articles and books about computing including Hello, Android: Introducing Google's Mobile Development Platform, 2nd Edition. For disclosure of Ed's industry affiliations, click here or to view his full profile click here.

Email Ed Burnette

Subscribe to Dev Connection via Email alerts or RSS.

Talkback

Add your opinion

SponsoredWhite Papers, Webcasts, and Downloads

advertisement

Recent Entries

Archives

Favorite Links

ZDNet Blogs

White Papers, Webcasts, and Downloads

Meet Doc

  • Here to help you with your Document Management Needs
  • Doc is an enigma. Born to a Russian ballerina and a German electrical engineer, he grew up in various locations in the United States. He’s seen the insides of more brands, versions, and generations of printer and printer-related hardware than almost anyone.
  • To learn more about this mysterious figure check out his blog on ZDNet and his Workspace on TechRepublic. You’ll be glad you did.
  • Produced by
    ZDNet and