Game Development Reference
In-Depth Information
menting this code, using the double forward slash, would, however, generate compiler
errors in NetBeans 8.0:
i
mport
// This line of code imports the Stage
class
javafx.stage.Stage
Here, the compiler will see only the word
import
, as the single-line comment goes
to the end of the line, compared with the multiline comment, which is specifically
ended using the block comment delimiter sequence (asterisk and a forward slash). So,
the compiler will throw an error for this second improperly commented code, essen-
tially asking, “Import what?”
Just as the Java programming language uses the double forward slash and slash-as-
terisk pairing to
delimit
the comments in your Java code, so too a couple of other key
characters are used to delimit Java programming statements as well as entire blocks of
Java programming logic (I often call these Java code structures).
The
semicolon
is used in Java (all versions) to delimit or separate Java program-
ming statements, such as the package and import statements seen in
Figure 3-1
.
The
Java compiler looks for a Java keyword, which starts a Java statement, and then takes
everything after that keyword, up to the semicolon (which is the way to tell the Java
compiler, “I am done coding this Java statement”), as being part of the Java code state-
ment. For instance, to declare the Java package at the top of your Java application, you
use the Java
package
keyword, the name of your package, and then a semicolon, as
follows (see also
Figure 3-1
):
package
invincibagel;
Import statements are delimited using the semicolon as well, as can be seen in the
figure. The import statement provides the import keyword, the package and class to be
imported, and, finally, the semicolon delimiter, as shown in the following Java pro-
gramming statement:
import
javafx.application.Application;
Next, you should take a look at the
curly { braces
(
{. . .})
delimiter, which, like the
multiline comment delimiter, has an
opening curly brace
, which delimits (that is,
which shows a compiler) the start of a collection of Java statements, as well as a
clos-
ing curly brace
, which delimits the end of the collection of Java programming state-
ments. The curly braces allow you to use multiple Java programming statements inside
a number of Java constructs, including inside of Java classes, methods, loops, condi-