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 | 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". |
| 2 | f | Compile-time error | Variables declared inside of a block or method are called local variables; they are not automatically initialized. The compiler will generate an error as a result of the attempt to access the local variables before a value has been assigned. |
| 3 | d | 4 | 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 | g | None of the above | Section 12.1.4 of the Java Language Specification requires that the main method must accept a single argument that is an array of components of type String. In each of the three class declarations, the single argument is indeed an array of components of type String. Please note that the square brackets within an array declaration may appear as part of the type or part of the declarator (i.e. array name). |
| 5 | b | 2 | 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 | d | Prints: -128,127 | A byte is an 8 bit signed value; so the minimum byte value is -(27) and the maximum value is (27 - 1). |
| 7 | f g h | 6 7 8 | The compiler will implicitly do a narrowing conversion for an assignment statement if the right hand operand is a compile time constant of type byte, short, char, or int and the value falls within the range of the variable on the left and if the variable is of type byte, short, or char. |
| 8 | a e | 1 5 | An array creation expression must have either a dimension expression or an initializer. If both are present, then a compile-time error is generated. Similarly, if neither is present, then a compile-time error is generated. If only the dimension expression is present, then an array with the specified dimension is created with all elements set to the default values. If only the initializer is present, then an array will be created that has the required dimensions to accommodate the values specified in the initializer. Java avoids the possibility of an incompatible dimension expression and initializer by not allowing both to appear in the same array creation expression. A compile-time error is generated by the array creation expression for a1, because it needs either a dimension expression or an initializer. A compile-time error is generated at 5, because either the dimension expression or the initializer must be removed. |
| 9 | e f | An attempt to run GRC2 from the command line fails. An attempt to run GRC3 from the command line fails. | Section 12.1.4 of the JLS requires the main method to be declared public. The main methods of GRC2 and GRC3 are not declared public and can not be invoked from the command line using a JVM that is compliant with section 12.1.4. Not every JVM enforces the rule. Even so, for the purposes of the SCJP exam, the main method should be declared as required by the JLS. |
| 10 | b | Prints: -32768,32767 | A short is a 16 bit signed value; so the minimum short value is -(215) and the maximum value is (215 - 1). |
| 11 | b c f | 2 3 6 | The maximum value of type byte is 127. The minimum value of type short is -32768. The maximum value of type char is 65535. |
| 12 | b | Prints: 0,0,0.0,null | Each array contains the default value for its type. The default value of a primitive byte or a primitive long is printed as 0. The default value of a float primitive is printed as 0.0. The default value of an Object is null and is printed as null. |
| 13 | a | Prints: 1111111,177,127,7f |
A
byte
is an 8 bit signed value. The left most bit is the
sign bit. The sign bit is set to zero for positive numbers
and is set to one for negative numbers. The most positive
byte value is represented as a sign bit that is set to zero
and all of the other bits set to one. The
|
| 14 | a d e | 1 4 5 | The minimum value of type byte is -128. The maximum value of type short is 32767. The minimum value of type char is 0. |
| 15 | a e | transient volatile | Serializable, Runnable, Externalizable, and Cloneable are all interfaces. Thread.run is a method. The keywords transient and volatile are field modifiers. |
| 16 | e | Compile-time error at line 5. | The local variable y has not been initialized so the attempt to access the variable results in a compile-time error. |
| 17 | c | Prints: 0null | The numeric sum of variables a, b, c, d and e is zero. The zero is converted to a String and concatenated with s. |
| 18 | b g i | goto implements const | The words virtual, ifdef, typedef, friend, struct and union are all words related to the C programming language. Although the words const and goto are also related to the C programming language, they are also Java keywords. |
| 19 | d f h | 4 6 8 |
The first letter of an identifier can be any
|