Chapter 1: Beginning Android and Java
Welcome to Android Programming for Beginners Third Edition. In this first chapter, we won't waste any time getting started with developing Android apps. We will look at what is so great about Android, what exactly Android and Java are, how they work and complement each other, and what that means to us as future developers. Moving quickly on, we will set up the required software so we can build and deploy a simple first app.
Note
It is my aim to keep this book up to date. Please check the following web page for any discussion and tips on any changes to Android Studio since the book was first printed: http://gamecodeschool.com/books/android-programming-for-beginners-3rd-edition#android-studio-updates.
By the end of this chapter, we will have done the following:
- Discovered what is new in this third edition
- Learned how Java and Android work together
- Set up our development environment – Android Studio – which takes care of all the components involved in building the Android apps that we will learn about next
- Learned about the Java Development Kit (JDK) and the Android Application Programming Interface (API) and how we use them through Android Studio
- Built our very first Android app
- Deployed the app on an Android emulator
- Run our app on an Android emulator and a real device
That's a lot to get through, so let's get started.
Technical requirements
The following are the official technical requirements for Android development with Android Studio and its related tools. However, these are the absolute bare minimum. Please see the Setting up Android Studio section for further details.
The requirements for Windows are as follows:
- Microsoft® Windows® 7/8/10 (64-bit)
- 4 GB RAM as a minimum; 8 GB RAM recommended
- 2 GB of available disk space as a minimum; 4 GB recommended (500 MB for the Integrated Development Environment (IDE) + 1.5 GB for the Android Software Development Kit (SDK) and emulator system image)
- 1,280 x 800 minimum screen resolution
The requirements for Mac are as follows:
- Mac® OS X® 10.10 (Yosemite) or higher, up to 10.14 (macOS Mojave)
- 4 GB RAM as a minimum; 8 GB RAM recommended
- 2 GB of available disk space as a minimum; 4 GB recommended (500 MB for the IDE + 1.5 GB for the Android SDK and emulator system image)
- 1,280 x 800 minimum screen resolution
The requirements for Linux are as follows:
- GNOME or KDE desktop
- Tested on gLinux based on Debian
- 64-bit distribution capable of running 32-bit applications
- GNU C Library (glibc) 2.19 or later
- 4 GB RAM as a minimum; 8 GB RAM recommended
- 2 GB of available disk space as a minimum; 4 GB recommended (500 MB for the IDE + 1.5 GB for the Android SDK and emulator system image)
- 1,280 x 800 minimum screen resolution
You can find the code files present in this chapter on GitHub at https://github.com/PacktPublishing/Android-Programming-for-Beginners-Third-Edition/tree/main/chapter%2001.
What's new in the third edition?
The second edition saw huge amounts of additional topics compared to the first edition. Unfortunately, there are only so many pages that can fit in a paperback book. Therefore, this edition focuses on improving the way that the Java, Android, and app development concepts are taught. We have rethought the way that topics are explained and made it more visual than before. In addition, I have managed to squeeze in about a dozen new mini topics. These are either Java fundamentals such as variable types not covered in earlier editions, new Android Studio features such as the profiler, or classic programming concepts such as method recursion and the live debugging of our code. Hopefully, this third edition will therefore make your Android and Java journeys smoother and more complete.
Why Java and Android?
When Android first arrived in 2008, it was a bit drab compared to the much more stylish iOS on the Apple iPhone/iPad. But quite quickly, through diverse handset offerings that struck a chord with both the practical price-conscious as well as the fashion-conscious and tech-savvy, the Android user numbers exploded.
For many, myself included, developing for Android is the most rewarding pastime and business bar none.
Quickly putting together a prototype of an idea, refining it, and then deciding to run with it and wire it up into a fully fledged app is such an exciting and rewarding process. Any programming can be fun, and I have been programming all my life, but creating for Android is somehow extraordinarily rewarding.
Defining exactly why this is the case is quite difficult. Perhaps it is the fact that the platform is free and open source. You can distribute your apps without needing the permission of a big, controlling corporation – nobody can stop you. At the same time, you have well-established, corporate-controlled mass markets such as Amazon Appstore and Google Play.
More likely, the reason why developing for Android gives such a good feeling is the nature of the devices themselves. They are deeply personal. You can develop apps that interact with people's lives – educate, entertain, tell a story, and so on – and it is there in their pockets ready to go, in the home, in the workplace, or on holiday.
You can certainly build something bigger for the desktop. But knowing that thousands (or millions) of people are carrying your work in their pockets and sharing it with friends gives more than just a buzz.
In fact, developing for Android is considered highly skillful and the most successful developers are hugely admired, even revered.
If all this fluffy and spiritual stuff doesn't mean anything to you, then that's fine too; developing for Android can make you a living or even make you wealthy. With the continued growth of device ownership, the ongoing increase in CPU and GPU power, and the non-stop evolution of the Android operating system itself, the need for professional app developers is only going to grow.
In short, the best Android developers – and, more importantly, the Android developers with the best ideas and most determination – are in greater demand than ever. Nobody knows who these future Android app developers are and they might not even have written their first line of Java yet.
So, why isn't everybody an Android developer? Obviously, not everybody will share my enthusiasm for the thrill of creating software that can help people make their lives better, but I am guessing that because you are reading this, you might!
The beginner's first stumbling block
Unfortunately, for those that do share my enthusia...