Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Learning Java by Building Android  Games

You're reading from   Learning Java by Building Android Games Learn Java and Android from scratch by building six exciting games

Arrow left icon
Product type Paperback
Published in Aug 2018
Publisher
ISBN-13 9781788839150
Length 774 pages
Edition 2nd Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
John Horton John Horton
Author Profile Icon John Horton
John Horton
Arrow right icon
View More author details
Toc

Table of Contents (28) Chapters Close

Preface 1. Java, Android and Game Development FREE CHAPTER 2. Java: First Contact 3. Variables, Operators and Expressions 4. Structuring Code with Java Methods 5. The Android Canvas Class – Drawing to the Screen 6. Repeating Blocks of Code with Loops 7. Making Decisions with Java If, Else and Switch 8. Object-Oriented Programming 9. The Game Engine, Threads, and The Game Loop 10. Coding the Bat and Ball 11. Collisions, Sound Effects and Supporting Different Versions of Android 12. Handling Lots of Data with Arrays 13. Bitmap Graphics and Measuring Time 14. The Stack, the Heap, and the Garbage Collector 15. Android Localization -Hola! 16. Collections, Generics and Enumerations 17. Manipulating Bitmaps and Coding the Snake class 18. Introduction to Design Patterns and much more! 19. Listening with the Observer Pattern, Multitouch and Building a Particle System 20. More Patterns, a Scrolling Background and Building the Player's ship 21. Completing the Scrolling Shooter Game 22. Exploring More Patterns and Planning the Platformer Project 23. The Singleton Pattern, Java HashMap, Storing Bitmaps Efficiently and Designing Levels 24. Sprite-sheet animations, Controllable Player and Parallax Scrolling Backgrounds 25. Intelligent Platforms and Advanced Collision Detection 26. What next? Index

How Java and Android work

After we write a game in Java for Android, we click on a button in Android Studio to change our code into another form, a form that is understood by Android devices. We call this "other form" Dalvik EXecutable (DEX) code, and the transformation process is called compiling.

Compiling takes place on the development machine after we click on that button. We will see this work right after we set up our development environment in a minute.

Android is a complex system, but you do not need to understand it in depth, in fact, it is designed to hide the complexity, all operating systems are, and Android does this better than most.

The part of the Android system that executes (runs) our compiled DEX code is called the Dalvik Virtual Machine (DVM). The DVM itself is a piece of software that runs on a specially adapted version of the Linux operating system. So, what the user sees of Android, is, Android just as an app running on yet another operating system. Therefore the apps and games that we write are apps running on top of the app which is Android itself.

The purpose of the DVM is to hide the complexity and diversity of the hardware and software that Android runs on but, at the same time, its purpose is to expose all its useful features. This exposing of features works in two ways.

The DVM itself must have access to the hardware, which it does, but this access must be programmer friendly and easy to use. The way the DVM allows us access is indeed easy to use because of the Android Application Programming Interface (API).

This API is primarily designed to use with Java. In fact, most of the Android API, is itself, Java code. As I may have mentioned already, this makes Android games the most fun and thorough way to learn Android, Java and game development.

If you want to see the relationship between The Android API, DEX code, DVM and an Android device, look at this picture.

How Java and Android work

Tip

Don't worry too much about this initially convoluted sounding system, it is much more fun, quicker and easier to get to know how things work by writing some real code.

Let's set up Android Studio.

You have been reading a chapter from
Learning Java by Building Android Games - Second Edition
Published in: Aug 2018
Publisher:
ISBN-13: 9781788839150
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime