ptg7068951
62 HOUR 5:Storing and Changing Information in a Program
Q&A
Q. Is a line in a Java program the same thing as a statement?
A. No. The programs you create in this book put one statement on each
line to make the programs easier to understand; it’s not required.
The Java compiler does not consider lines,spacing,or other formatting
issues when compiling a program. The compiler just wants to see semi-
colons at the end of each statement. This line would work just fine in Java:
int x = 12; x = x + 1;
Putting more than one statement on a line makes a program more diffi-
cult for humans to understand when they read its source code. For this
reason,it is not recommended.
Q. Why should the first letter of a variable name be lowercase,as in
gameOver?
A. It’s a naming convention that helps your programming in two ways. First,
it makes variables easier to spot among the other elements of a Java
program. Second,by following a consistent style in the naming of vari-
ables,you eliminate errors that can occur when you use a variable in
several different places in a program. The style of capitalization used in
this book is the one that’s been adopted by most Java programmers over
the years.
Q. Can I specify integers as binary values in Java?
A. Yo u c a n f o r t h e f i r s t t i m e i n J av a 7. P u t t h e c h a r a c t e r s 0bin front of the
number and follow it with the bits in the value. Because 1101 is the binary
form for the number 13,the following statement sets an integer to 13:
int z = 0b0000_1101;
The underscore is just to make the number more readable. It’s ignored
by the Java compiler.
NetBeans will treat this feature as an error unless your project has been
set up to use Java 7. You learn how to do this in Hour 7.
Q. What the heck are Larvets?
A. Larvets,the product mentioned in this hour,are snacks made from edi-
ble worms that have been killed,dried,and mixed with the same kinds
of scrumptious food-like flavoring as Doritos chips. You can order Larvets
in three flavors—BBQ,cheddar cheese,and Mexican spice—from the
mail-order retailer HotLix at the website http://www.hotlix.com or by calling
1-800-EAT-WORM.