Book Image

Learning Java by Building Android Games

By : John Horton
Book Image

Learning Java by Building Android Games

By: John Horton

Overview of this book

Table of Contents (17 chapters)
Learning Java by Building Android Games
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Why Android and Java?


A part of successful learning is the commitment by the student, not just to do the work, but in their belief that they are doing the right thing in the right way. So many technology-based courses and books don't get that commitment from the reader, not subconsciously anyway.

The problem is the students' belief that they might be, partly at least, wasting their time with something that is or will soon become outdated or perhaps is not quite right for them. This can be true to a large extent with programming. So why should you spend your finite time learning Java, on Android?

Android is the fastest evolving and growing OS ever

At one time, Android updates emerged almost every two months. Even now, they emerge about once in six months. By comparison, Windows takes years between versions and even iOS updates come only yearly and usually change relatively little between versions. Android is obviously evolving and improving at an unprecedented rate.

Tip

Look at the history of Android versions since Version 1 at http://www.cnet.com/news/history-of-android/.

The first humble version of Android was released in 2008, around the same time when consumers were already quite excited about the then much flashier iPhone. News stories were also reporting that developers were getting rich by selling apps in the iTunes app store.

But in the last full year before this book was written, Samsung alone shipped more Android units than Apple sold all iOS devices combined. I am not joining the war on whose devices are best. I enjoy aspects of both Android and Apple, but purely in terms of picking a platform to learn on, you are probably in the right place at the right time with Android.

Android developers have great prospects

Now you might have picked up this book just for the fun and satisfaction that comes with learning to program games. But if you decide to develop your learning further, you will find that the demand for Android programmers is enormous and therefore very lucrative too.

Tip

Some data suggests salaries in excess of 100,000 US dollars. For more information, go to http://www.indeed.com/salary?q1=Android+Developer&l1=United+States.

Android is open source

What open source means is that although Google develops all the flavors of Android that are used on the newest devices, once the code is released, anybody can do whatever they like with it. Google only exerts control for a limited amount of time.

In practice, most Android users have the pure Google OS or the modified versions turned out by big manufacturers such as Samsung and HTC, but there is nothing to stop anybody taking the OS and changing, adapting, or converting it into whatever they like. In short, Android could never be taken away from the programming community.

Java is here to stay

Okay, so we see Android isn't likely to disappear but could Java become redundant? And will your significant time investment be wasted? On Android, as with most platforms, you can use many languages and tools. Android, however, was designed from the ground up to facilitate Java development. All other languages and tools are not invalid but tend to serve a fairly specific purpose, rather than be a real alternative to Java. In fact, as far as games are concerned, many of the alternatives to a pure Java development environment are also Java-based and require a good level of skill in Java to use. For example, the popular LibGDX game development library, which allows you to simultaneously make games for Android, iOS, Windows, Linux, Mac and even the Web, still uses Java! We will talk more about this in Chapter 9, Making Your Game the Next Big Thing. The point is that Java and Android are tied together and will likely thrive together.

Java is not just for Android

Java has been around a lot longer than Android, since the beginning of the 1990s in fact. Although what Java has been used for has evolved and diversified over more than two decades, the originally implemented strengths of the language itself remain the same today.

Java was designed to be platform- or computer-independent. This is achieved by the use of a virtual machine (VM). This is a program written in another language that decodes the Java program that we write and interacts with the computer platform it is running on. So as long as there is a VM for the computer you want to run your Java program on, with a few caveats, your Java program will work. So if you learn Java, you are learning a language that is used everywhere from the smart fridge to the Web and most places in between.

It is true, however, that the VM on each platform can and usually does implement features to specifically suit the uses it is likely to be put to. A clear example of this would be mobile-device-specific features such as sensors, GPS, or the built-in camera on many Android devices. Using Java with Android, you can take photos, detect the air pressure, and work out exactly where in the world you are. Most fridge VMs probably will not do this. So you can't always just run a Java program designed for device x on device y, but the language and syntax is the same. Learning Java on Android prepares you in a large part for Java in any situation. So rest assured that Java isn't going away any time soon.

Java is fast and easy to use

There is a decades-long debate over which language is the best overall or which language is the best to learn programming. Critics of Java will likely say things about Java's speed. It is true that the Java memory management along with the VM interpretation process does have some speed cost. However, these things have benefits; they significantly improve our productivity and the way that the Android VM interacts with a device largely negates the minor speed penalty. And since Android 4.4, it does so completely with Android Run Time (ART), which installs apps written in Java as fully native applications. Now Java programmers can build games in a friendly, interpreted language and have them run as if they were written in a more challenging natively compiled language.

A summary of Java and Android

In a rapidly changing world, if you are worried about where to invest your precious learning time, it is hard to have more confidence. Here we have a language (Java) whose fundamentals have remained almost the same for nearly a quarter of a century, and a platform (Android) that is backed by the biggest names in hardware, software, and retail, and though it's admittedly hugely influenced, it's not actually owned by anyone.

I am not an evangelist of any technology over another although it is true that I love doing stuff on Android. But you can be sure in your mind that if you are considering the best path to begin learning programming, there is a very strong argument that Java and Android are the best choice.

If you want to learn Java for any of its numerous uses, then this is a very good place to start. If you want to develop for Android or get into Android development of any sort, then Java is the absolute fundamental way to start, and making games has the enormous benefits we have already discussed.

By the end of the book, you will be able to write Java code for almost any Java-supported platform. You will be able use almost everything you learn in this book, away from the Android environment.

If you are planning to pursue a career or business by making Android games or any Android apps, then this book is possibly the only place to start for beginners.

If you are completely new to Java and want the easiest possible path to mastering it—the fastest growing platform on the planet—then Learning Java by Building Android Games will probably be just right for you.

So hopefully you are assured that the path this book will take to learn Java is as easy, fun, and thorough as learning Java can be. Let's get set up so we can start building games.