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 BookSurge.com.
Are you a university student studying Java programming? Do you agree that my book would serve as a helpful workbook and companion to be used along with the Java fundamentals textbook that is currently being used in your class? If so, then please ask your professor to consider using my book in future classes.
If you have any questions or comments concerning my mock exams or my book, then please send an e-mail to me at scjpexam2000@yahoo.com.
I would also like to read your response to the following questions.
| 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 | 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". |
| 3 | 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". |
| 4 | 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". |
| 5 | 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". |
| 6 | 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". |
| 7 | b | Prints: null | The System.out.print method prints the word null if the argument is a String reference that is null. |
| 8 | f | None of the above | Floating-point literals are covered in section 3.10.2 of the JLS. A floating-point literal can begin with either a digit or a decimal point. Optionally, it can have a fractional part, an exponent part and a floating point suffix--f, F, d, or D. |
| 9 | d | 4 | The literal 1.0 is a double and can not be used to initialize a float without an explicit cast. |
| 10 | c d | 3 4 | The compiler interprets \u000a as a line terminator. The escape sequence \n should be used instead. Similarly, \u000d is interpreted as a line terminator. The escape sequence \r should be used instead. |
| 11 | f | None of the above | All of the declarations are legal. String b is a single quote followed by the letter A followed by another single quote. String c is the letter A. String d is the Unicode character that is represented by the hexadecimal value D7AF. String literals are covered in section 3.10.5 of the JLS. |
| 12 | e | None of the above | String literals are declared using double quotes, but all of the declarations here use single quotes. |
| 13 | e | None of the above | Unicode char literals are declared using single quotes, but none of the declarations here use single quotes. The declaration of char b, is also problematic, because it contains more than one char. |
| 14 | f | None of the above | All of the declarations are legal. The first three ( 061, '\61', '\061' ) are declared in octal format. The fourth (0x0031) is declared as a hexadecimal literal. The fifth ('\u0031') is a Unicode escape sequence. |
| 15 | d e | 4 5 | All of the escape sequences used in this question are defined for the C programming language. Those that are not also Java escape sequences result in a compile-time error. Java does not accept the hexadecimal escape sequences of the C programming language. However, Java does accept Unicode escapes (JLS 3.3). |
| 16 | b | 2 | The reference a1 is set to null. String b1 generates a compile-time error, because String literals must be enclosed by double quotes. String c1 is the word null. String d1 is a single quote followed by the word null followed by another single quote. String literals are covered in section 3.10.5 of the JLS. |
| 17 | d | char d = -1; | The assignment of -1 to char d generates a compile-time error, because the primitive char type is unsigned. A negative int can not be assigned to a char without an explicit cast. If the literal value -1 were cast to type char then the result would be \uffff. |
| 18 | a | boolean b1 = true; | There are two primitive boolean values: true and false. Both must be written with lower case letters. Although the C programming language accepts zero as a boolean value, the Java programming language does not. |