Organize Instructions into Functions
So now that you can store all kinds of data in variables, next you need to learn how to write instructions to do fun actions with all that data, from printing messages to flinging flaming cows in Minecraft.
As you’ve seen, you can also tell Java to do things. In Java, you organize lines of code (instructions) inside a pair of curly braces, like { and }. You give that section of code a name, and those instructions will be run in order, one line after another. We call that a function (sometimes we’ll call it a method; for now they mean mostly the same thing).
Why do we bother with functions at all? Couldn’t we just have one big list of instructions and be done? Well, yes, we could, but it can get very confusing ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access