Page 138 - Introduction to Programming with Java: A Problem Solving Approach
P. 138
104 Chapter 3 Java Basics Review Question Solutions
1. It generates the output: I have a dream!
2. The Java source code extension is .java. The bytecode extension is .class.
3. Source code has comments to help Java programmers recall or determine how a program works. (Comments are ignored by the computer, and they are not accessible to ordinary users.) The initial comment block includes the file name as a continuous reminder to the programmer. It contains program authors,
for help and reference. It may include date and version number to identify context. It includes a short descriptiontofacilitaterapidunderstanding.Punctuationcommentslike// end class <class-name> help keep a reader oriented. Special comments identify variables and annotate obscure formulas.
4. True. If a file has a public class, the filename must equal this class name.
5. False. Class names should start with an uppercase first letter.
6. True. Java is case sensitive. Changing the case of any letter creates a completely different identifier.
7. True.
8. True. Otherwise, the startup procedure cannot be accessed.
9. public static void main(String[] args)
10. One must use braces for (1) all the contents of a class and (2) all the contents of a method.
11. System.out.println("Here is an example");
Apago PDF Enhancer
12. Upper-case characters, lower-case characters, numbers, underscore, and dollar sign.
13. Upper-case characters, lower-case characters, underscore, and dollar sign. No numbers.
14. False: In source code, saving space is not as important as good communication. Weird abbreviations are hard to say and not as easy to remember as real words.
15. If each variable is on a separate line, each variable has space at the right for an elaborating comment.
16. True.
17. Variable declaration and assigning a value into the variable.
18. Type double, or type long, with value in cents.
19. a) True; b) False; c) True
20. Assigning an integer value into a floating point variable is like putting a small object into a large box. The int type goes up to approximately 2 billion. It’s easy to fit 2 billion into a double “box” because a double goes all the way up to 1.8 10308. On the other hand, assigning a floating point value into an integer variable is like putting a large object into a small box. By default, that’s illegal.
21. a) False; b) True; c) True; d) True
22. The final modifier specifies that a variable’s value is fixed/constant.
23. The remainder operator is a percent sign: %.
24. Write the following mathematical expressions as legal Java expressions:
a) (3 * x 1) / (x * x)
b) 1.0 / 2 1.0 / (x * y) or
.5 1.0 / (x * y)