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

■ ■Definition A “convention” in <strong>Java</strong> programming is the way that most, if not all, <strong>Java</strong> programmers will implement a<br />

<strong>Java</strong> construct. In this case, this is the way that the <strong>Java</strong> code block commenting is styled.<br />

There is a third type of comment, called a <strong>Java</strong>doc comment, which you will not be using in your <strong>Java</strong> 8 game<br />

development, as your code is intended to be used to create a game, and not to be distributed to the public. If you were<br />

going to write a <strong>Java</strong> game engine for use by others to create games, that is when you would use <strong>Java</strong>doc comments to<br />

add documentation to your <strong>Java</strong> 8 game engine. A <strong>Java</strong>doc comment can be used by the javadoc.exe tool in the JDK<br />

to generate HTML documentation for the <strong>Java</strong> class containing <strong>Java</strong>doc comments, based on the text content that you<br />

put inside the <strong>Java</strong>doc comment.<br />

A <strong>Java</strong>doc comment is similar to a multiline comment, but it uses instead two asterisks to create the opening<br />

<strong>Java</strong>doc comment delimiter, as shown here:<br />

/** This is an example of a <strong>Java</strong> Documentation (<strong>Java</strong>doc) type of <strong>Java</strong> code comment.<br />

This is a type of comment which will automatically generate <strong>Java</strong> documentation!<br />

*/<br />

If you wanted to insert a comment right in the middle of your <strong>Java</strong> statement or programming structure<br />

(which you should never do as a professional <strong>Java</strong> programmer), use the multiline comment format, like so:<br />

import /* This line of code imports the Stage class */ javafx.stage.Stage;<br />

This will not generate any errors, but would confuse the readers of this code, so do not comment your code in<br />

this way. The following single line comment way of commenting this code, using the double forward slash, would,<br />

however, generate compiler errors in NetBeans 8.0:<br />

import // This line of code imports the Stage class javafx.stage.Stage<br />

Here, the compiler will see only the word import, as the single-line comment goes to the end of the line,<br />

compared with the multiline comment, which is specifically ended using the block comment delimiter sequence<br />

(asterisk and a forward slash). So, the compiler will throw an error for this second improperly commented code,<br />

essentially asking, “Import what?”<br />

Just as the <strong>Java</strong> programming language uses the double forward slash and slash-asterisk pairing to delimit the<br />

comments in your <strong>Java</strong> code, so too a couple of other key characters are used to delimit <strong>Java</strong> programming statements<br />

as well as entire blocks of <strong>Java</strong> programming logic (I often call these <strong>Java</strong> code structures).<br />

The semicolon is used in <strong>Java</strong> (all versions) to delimit or separate <strong>Java</strong> programming statements, such as the<br />

package and import statements seen in Figure 3-1. The <strong>Java</strong> compiler looks for a <strong>Java</strong> keyword, which starts a <strong>Java</strong><br />

statement, and then takes everything after that keyword, up to the semicolon (which is the way to tell the <strong>Java</strong><br />

compiler, “I am done coding this <strong>Java</strong> statement”), as being part of the <strong>Java</strong> code statement. For instance, to declare<br />

the <strong>Java</strong> package at the top of your <strong>Java</strong> application, you use the <strong>Java</strong> package keyword, the name of your package, and<br />

then a semicolon, as follows (see also Figure 3-1):<br />

package invincibagel;<br />

Import statements are delimited using the semicolon as well, as can be seen in the figure. The import statement<br />

provides the import keyword, the package and class to be imported, and, finally, the semicolon delimiter, as shown<br />

in the following <strong>Java</strong> programming statement:<br />

import javafx.application.Application;<br />

www.it-ebooks.info<br />

45

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

Saved successfully!

Ooh no, something went wrong!