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 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. |
| 7 | 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". |
| 8 | 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". |
| 9 | l | None of the above | All of these are keywords of the Pascal programming language, but none are Java keywords. |
| 10 | 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). |
| 11 | 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. |
| 12 | 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). |
| 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 | 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. |
| 15 | 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. |
| 16 | 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. |
| 17 | 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. |
| 18 | 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. |
| 19 | 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. |
| 20 | 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. |
| 21 | 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. |
| 22 | d | import, break, double, exception, throws | The word exception is not a Java keyword. The words import, break, double and throws are Java keywords. |
| 23 | 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. |
| 24 | d f h | 4 6 8 |
The first letter of an identifier can be any
|