28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 3 ■ A <strong>Java</strong> 8 Primer: An Introduction to <strong>Java</strong> 8 Concepts and Principles<br />

Next, you should take a look at the curly { braces ({. . .}) delimiter, which, like the multiline comment delimiter,<br />

has an opening curly brace, which delimits (that is, which shows a compiler) the start of a collection of <strong>Java</strong><br />

statements, as well as a closing curly brace, which delimits the end of the collection of <strong>Java</strong> programming statements.<br />

The curly braces allow you to use multiple <strong>Java</strong> programming statements inside a number of <strong>Java</strong> constructs,<br />

including inside of <strong>Java</strong> classes, methods, loops, conditional statements, lambda expressions, and interfaces, all of<br />

which you will be learning about over the course of this book.<br />

As illustrated in Figure 3-2, <strong>Java</strong> code blocks delimited using curly braces can be nested (contained) inside of<br />

each other, allowing far more complex <strong>Java</strong> code constructs. The first (outermost) code block using curly braces is<br />

the InvinciBagel class, with other constructs then nested as follows: the start() method, the .setOnAction() method,<br />

and the handle() method. You will be examining what all this code does as this chapter progresses. What I want you<br />

to visualize now (with the help of the red squares in Figure 3.2) is how the curly braces are allowing your methods<br />

(and class) to define their own code blocks (structures), each of which is a part of a larger <strong>Java</strong> structure, with the<br />

largest <strong>Java</strong> structure being the InvinciBagel.java class itself. Note how each opening curly brace has a matching<br />

closing curly brace. Note as well the indenting of the code, such that the innermost <strong>Java</strong> code structures are indented<br />

the farthest to the right. Each block of code is indented by an additional four characters or spaces. As you can see,<br />

the class is not indented (0), the start() method is 4 spaces in, the .setOnAction() method is 8 spaces in, and the<br />

handle() method is 12 spaces in. NetBeans 8.0 will indent each of your <strong>Java</strong> code structures for you! Also notice that<br />

NetBeans 8.0 draws very fine (gray) indentation guide lines in the IDE so that you can line up your code structures<br />

visually, if you prefer.<br />

Figure 3-2. Nested <strong>Java</strong> code blocks for the InvinciBagel class, start method, setOnAction method, and handle method<br />

The <strong>Java</strong> code inside each of the red squares begins with a curly brace and ends with a curly brace. Now that you<br />

are familiar with the various <strong>Java</strong> 8 code commenting approaches, as well as how your <strong>Java</strong> 8 game programming<br />

statements need to be delimited, both individually and as <strong>Java</strong> code blocks, you will next study the various <strong>Java</strong> code<br />

structures themselves—how they are used, what they can do for your applications and games, and which important<br />

<strong>Java</strong> keywords are employed to implement them.<br />

46<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!