28.04.2019 Views

[JAVA][Beginning Java 8 Games Development]

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

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

JDK compiler (program) turns your <strong>Java</strong> code into bytecode that is executed or run by a <strong>Java</strong> Runtime Engine (JRE).<br />

This JRE, in this case it is JRE 8, is installed on your end user’s computer system. The <strong>Java</strong> compiler needs to know<br />

where your <strong>Java</strong> code blocks begin and end, where your individual <strong>Java</strong> programming statements or instructions<br />

begin and end within those <strong>Java</strong> code blocks, and which parts of your code are <strong>Java</strong> programming logic, and which<br />

parts are comments to yourself, or comments (notes) to other members of your game project programming team.<br />

Let’s start with comments, as this topic is the easiest to grasp, and you have already seen comments in your<br />

InvinciBagel game bootstrap <strong>Java</strong> code, in Chapter 2. There are two ways to add comments into <strong>Java</strong> code: single-line,<br />

also referred to as “in-line,” comments, which are placed after a line of <strong>Java</strong> code logic, and multiple--line, or “block,”<br />

comments, which are placed before (or after) a line of <strong>Java</strong> code or a block of <strong>Java</strong> code (a <strong>Java</strong> code structure).<br />

The single-line comment is usually utilized to add a comment regarding what that line of <strong>Java</strong> logic, which I like<br />

to call a <strong>Java</strong> programming “statement,” is doing, that is, what that line of <strong>Java</strong> code is there to accomplish within your<br />

overall code structure. Single-line comments in <strong>Java</strong> start with the double forward slash sequence. For instance, if<br />

you wanted to comment one of the import statements in the InvinciBagel bootstrap code that you created in Chapter 2,<br />

you would add double forward slashes after the line of code. This is what your <strong>Java</strong> code would look like once it has<br />

been commented (see also Figure 3-1, bottom right):<br />

import javafx.stage.Stage // This line of code imports the Stage class from <strong>Java</strong>FX.stage package<br />

Figure 3-1. Multiline comments ( first five lines of code, at the top) and single-line comments (last three lines of code, at<br />

the bottom)<br />

Next, let’s take a look at multiline comments, which are shown at the top of Figure 3-1, above the package<br />

statement (which you will be learning about in the next section). As you can see, these <strong>Java</strong> block comments are done<br />

differently, using a single forward slash next to an asterisk to start the comment and the reverse of that, an asterisk<br />

next to a single forward slash, to end the multi-line comment.<br />

As you can see in the InvinciBagel.java code editing tab in NetBeans 8.0, just as I lined up the single-line<br />

comments to look pretty (cool) and organized, so too the <strong>Java</strong> convention in block commenting is to line up the<br />

asterisks, with one as the beginning comment delimiter and one as the ending comment delimiter.<br />

44<br />

www.it-ebooks.info

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

Saved successfully!

Ooh no, something went wrong!