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
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

Methods

So what exactly are Java methods? A method is a collection of variables, expressions, and control flow statements. We have already been using lots of methods; we just haven't looked inside any yet.

Learning about Java methods will be the last topic for this chapter before we get practical and use what we have learned to enhance our math game.

The structure of a method

The first part of a method that we write is called the signature. Here is a made-up example of a signature:

public boolean shootLazers(int number, string type)

Add an opening and closing pair of curly braces with some code that the method performs, and we have a complete method, or a definition. Here is a made-up but syntactically correct method:

private void setCoordinates(int x, int y){
  //code to set coordinates goes here
}

We could then use our new method from another part of our code, like this:

//I like it here

setCoordinates(4,6);//now I am going off to setCoordinates method

//Phew, I'm back again - code...
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