Wednesday, 21 September 2011

Android for the Java Developer - part 1

In this article, we will look at beginning Android development from a Java programmer's perspective. We will take a look at the similarities and differences between Java and Android, and consider how these may affect how best to develop an Android app. The information may assist if you are, for example:
  • Converting an existing Java program to Android.
  • Developing an application for both Java and Android.
  • Have some experience with Java and want to learn Android.

Android can be thought of as a direct descendant of Java. Not only do the languages share are large common core, but also many existing Java libraries can be used in Android apps directly and without modification or recompilation. This makes Android a relatively easy step for anyone who has a Java background.

Let's take a look at some of the well-known package names from the Java SDK. Those on the left are also included in Android. Those on the right are in Java only.
Packages in Java AND Android ¹ Packages in Java but NOT Android
  • java.beans
  • java.lang
  • java.math
  • java.nio
  • java.sql
  • java.text
  • java.util
  • javax.crypto
  • javax.sql
  • javax.xml
  • java.applet
  • java.awt
  • java.rmi
  • javax.sound
  • javax.swing
¹ Top level packages only, not an exhaustive list.

It's clear that a very large chunk of the JDK is available to the Android developer. In addition, because Java libraries can incorporated into an Android app, it means any existing Java library can be used as long as it only needs packages from the left-hand column.

Turning now to the right-hand column, arguably the most significant "missing" packages are the ones related to user interface building, java.awt and javax.swing. This is because Android has its own system for building UI elements - more on this in another article coming soon.

So what to conclude from this, and how should it affect the design of an Android app we might want to build? Good application design should separate the core program logic from the user interface. If this principle is used, it will also make life easier should you want work with both Java and Android. The program logic parts of the app are typically going to use packages common to both languages, and hence can be easily reused.

A pure Java user interface cannot be reused however, and so an Android-specific version will need to be built. We will look at aspect more in the next article (coming soon).

For those developing an application for both Java and Android, or wanting to migrate an existing Java application to Android, here is a simplified diagram of how an app might be structured.

In the next article, we will explore in more detail the differences between Java and Android, and how we might navigate these to build our Android app.


  1. Thanks for the post, I am techno savvy. I believe you hit the nail right on the head. I am highly impressed with your blog. It is very nicely explained. Your article adds best knowledge to our Java Online Training from India. or learn thru Java EE Online Training Students.

  2. Wow, What a Excellent post. I really found this to much informatics. It is what i was searching for.I would like to suggest you that please keep sharing such type of info.Thanks website build

  3. Superbly written article, if only all bloggers offered the same content as you, the internet would be a far better place.. webdesign ny

  4. This article gives the light in which we can observe the reality. This is very nice one and gives in-depth information. Thanks for this nice article. Sondora SA

  5. I'm glad I found this web site, I couldn't find any knowledge on this matter prior to.Also operate a site and if you are ever interested in doing some visitor writing for me if possible feel free to let me know, im always look for people to check out my web site.
    Mason Soiza

  6. This is my first time visit here. From the tons of comments on your articles,I guess I am not only one having all the enjoyment right here!
    Mason Soiza