The pages of this web site are not formatted to conserve paper, but my new book (ISBN: 0-9745862-0-X) is formatted to save paper, save your printer cartridge, save a loose-leaf binder, and save money. If you prefer to work my exams from printed pages, then give your printer a rest and buy my new book.
Today, you can find my book at amazon.com.
| No. | Answer | Remark | |
|---|---|---|---|
| 1 | d e f | An attempt to run GRC7 from the command line fails. An attempt to run GRC8 from the command line fails. An attempt to run GRC9 from the command line fails. | Section 12.1.4 of the JLS requires the main method to be declared static. In this example, each of the three main methods are not declared static. The result is an error at run-time. |
| 2 | a | 1 | The escape sequences are as follows: '\b' (backspace), '\f' (formfeed), '\n' (newline), '\r' (carriage return), '\t' (horizontal tab), '\\' (backslash), '\"' (double quote), '\'' (single quote). Yes, you must memorize the escape sequences! Just remember "big farms need red tractors". |
| 3 | c | 3 | The escape sequences are as follows: '\b' (backspace), '\f' (formfeed), '\n' (newline), '\r' (carriage return), '\t' (horizontal tab), '\\' (backslash), '\"' (double quote), '\'' (single quote). Yes, you must memorize the escape sequences! Just remember "big farms need red tractors". |
| 4 | l | None of the above | All of these are keywords of the Pascal programming language, but none are Java keywords. |
| 5 | e | 5 | The escape sequences are as follows: '\b' (backspace), '\f' (formfeed), '\n' (newline), '\r' (carriage return), '\t' (horizontal tab), '\\' (backslash), '\"' (double quote), '\'' (single quote). Yes, you must memorize the escape sequences! Just remember "big farms need red tractors". |
| 6 | b d g h | strictfp super goto native | |
| 7 | b | Prints: null | The System.out.print method prints the word null if the argument is a String reference that is null. |
| 8 | e | Prints: 2,5,8 | Arrays a1, a2 and a3 all contain 3 integers. The first element of the array has an index of 0 so an index of one refers to the second element of each array. |
| 9 | c | Prints: 7f,ffff,7fff | A byte is an 8 bit signed value. A char is a 16 bit unsigned value. A short is a 16 bit signed value. The left most bit of a signed value is the sign bit. The sign bit is zero for positive numbers and one for negative numbers. The maximum byte value in hexadecimal format is 7f and in decimal format is 127. The minimum byte value in hexadecimal format is 80 and in decimal format is -128. The byte value of decimal -1 is ff in hexadecimal. |
| 10 | a | 1 | A compile-time error occurs at the line marked 1, because the array reference declaration can not be used to declare the number of components contained in the array. Instead, the dimension expression should be contained in an array creation expression such as new int[5]. |
| 11 | f | Prints: 80000000,7fffffff | An int is a 32 bit signed value. The left most bit is the sign bit. The sign bit is zero for positive numbers and one for negative numbers. |
| 12 | b d | '\u0000' to '\uffff' 0 to 65535 | A char is a 16 bit unsigned value; so none of the char values are negative and the minimum value is zero. The maximum value is 216 - 1. |
| 13 | b d f | 0x0000 to 0xffff 0 to 0177777 0 to 65535 | A char is a 16 bit unsigned value; so none of the char values are negative and the minimum value is zero. The maximum value is 216 - 1. |
| 14 | a | Prints: 0,0,0,0,0,null | The default value of type char is the null character. When it is cast to an int the value is interpreted as zero. |
| 15 | c | Prints: 0,0.0,0.0,false,null | Generally speaking, numeric type variables are initialized to zero. Primitive boolean variables are initialized to false. Reference type variables are initialized to null. |
| 16 | e | Compile-time error | Variable b1 is initialized to false, because it is a class member. The array component array[0] is initialized to the default value, false, of the array type, boolean[], even though the array is declared locally. Local variable b2 is not initialized, because it is local. A compile-time error is generated by the statement that attempts to print the value of b2. |
| 17 | c | Compile-time error | Local variables are not initialized automatically, and must be initialized explicitly before attempting to access the value. The local variable i3 will not be initialized if i1 is less than or equal to zero; so the result is a compile-time error. |
| 18 | d | import, break, double, exception, throws | The word exception is not a Java keyword. The words import, break, double and throws are Java keywords. |
| 19 | e | continue, finalize, goto, package, synchronized | The word finalize is the name of a method of the Object class: It is not a keyword. The words continue, goto, package and synchronized are all Java keywords. |