Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Book Overview & Buying Learning Java by Building Android Games
  • Table Of Contents Toc
  • Feedback & Rating feedback
Learning Java by Building Android Games

Learning Java by Building Android Games

By : John Horton
3.9 (30)
close
close
Learning Java by Building Android Games

Learning Java by Building Android Games

3.9 (30)
By: John Horton

Overview of this book

If you are completely new to either Java, Android, or game programming and are aiming to publish Android games, then this book is for you. This book also acts as a refresher for those who already have experience in Java on another platforms or other object-oriented languages.
Table of Contents (12 chapters)
close
close
11
Index

Java arrays – an array of variables

You might be wondering what happens when we have a game with lots of variables to keep track of. How about a table of high scores with the top 100 scores? We could declare and initialize 100 separate variables like this:

int topScore1;
int topScore2;
int topScore3;
//96 more lines like the above
int topScore100;

Straightaway, this can seem unwieldy, and what about the case when someone gets a new top score and we have to shift the scores in every variable down one place? A nightmare begins:

topScore100 = topScore99;
topScore99 = topScore98;
topScore98 = topScore97;
//96 more lines like the above
topScore1 = score;

There must be a better way to update the scores. When we have a large set of variables, what we need is a Java array. An array is a reference variable that holds up to a fixed maximum number of elements. Each element is a variable with a consistent type.

The following line of code declares an array that can hold int type variables, even a...

Visually different images
CONTINUE READING
83
Tech Concepts
36
Programming languages
73
Tech Tools
Icon Unlimited access to the largest independent learning library in tech of over 8,000 expert-authored tech books and videos.
Icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Icon 50+ new titles added per month and exclusive early access to books as they are being written.
Learning Java by Building Android Games
notes
bookmark Notes and Bookmarks search Search in title playlist Add to playlist font-size Font size

Change the font size

margin-width Margin width

Change margin width

day-mode Day/Sepia/Night Modes

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Confirmation

Modal Close icon
claim successful

Buy this book with your credits?

Modal Close icon
Are you sure you want to buy this book with one of your credits?
Close
YES, BUY

Submit Your Feedback

Modal Close icon
Modal Close icon
Modal Close icon