Chapter 1. Greetings, Mobile App Developers

Greetings, welcome, and guten tag. If you’ve picked up this book, it’s probably because you were attracted to the idea of building mobile apps for non-Java platforms with Java. You might not be familiar with GWT and PhoneGap. That’s okay. I’ll explain it all as we go forward. The important thing is that we are here to create great mobile apps.

The actual technology used to build software doesn’t really matter to the end user. People just want quality apps that look great and perform well. Unfortunately, the technology does matter when it comes down to actually building apps. Different platforms have their own toolchains and preferred languages. iPhone and iPad apps are largely written in Objective-C. Android apps are written in Google’s variant of Java. Windows Metro style apps use C#, C++, or Visual Basic. Add in webOS, BlackBerry (both old and new OSes), the Nook (older Android), and Kindle Fire (forked Android), and now we’ve got a problem.

To support all users we have to write our app at least three times, possibly many more if you count emerging TV platforms. And that’s the good news. The bad news is that it will only get worse. Mobile platforms are dividing not converging. Even among the Android family there are several major versions in widespread use, and the upgrade rate is sadly low.

So what is an enterprising app developer to do? You want to write an app once, not over and over again. We need a single platform that will work everywhere. Fortunately we already have such a platform: the Web. I’m not speaking about the Web as a network of computers which host HTML content. I’m speaking about the Web technologies HTML, JavaScript, and CSS. Virtually every OS has a web browser, which means it has a way to render HTML and JavaScript. In almost every case there is a way to build a local installable app using HTML and JavaScript. Great! We have a single platform. Problem solved. What now?

Well, if it were that easy we wouldn’t need this book. Every OS is different. They each have different support for HTML standards, JavaScript APIs, and native packaging systems. Plus, you would have to write everything in JavaScript rather than the Java code you are likely familiar with. You would have to give up static typing, the large ecosystem of Java libraries, and the great IDE experience we all enjoy. Well, that’s why you bought this book.

There are two amazing open source tools which will solve the problem for us: GWT and PhoneGap. GWT allows you to write Java but compile into cross-platform, works everywhere, JavaScript and HTML. PhoneGap provides native packaging for each OS, along with API wrappers for device features like the camera, accelerometer, and GPS radio. By their powers combined we can fulfill the dream: write once in a powerful and well supported statically typed language, Java, then produce native apps for every platform with a single codebase. Is the dream too good to be true? As we shall see, it is indeed quite real.

Get Building Mobile Applications with Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.