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.
class EBH019 {
public static void main (String args[]) {
int i1 = 0xffffffff, i2 = i1 << 1;
int i3 = i1 >> 1, i4 = i1 >>> 1;
System.out.print(Integer.toHexString(i2) + ",");
System.out.print(Integer.toHexString(i3) + ",");
System.out.print(Integer.toHexString(i4));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: ffffffff,ffffffff,ffffffff |
| b. | Prints: ffffffff,ffffffff,7fffffff |
| c. | Prints: ffffffff,7fffffff,ffffffff |
| d. | Prints: ffffffff,7ffffffe,7ffffffe |
| e. | Prints: fffffffe,ffffffff,ffffffff |
| f. | Prints: fffffffe,ffffffff,7fffffff |
| g. | Prints: fffffffe,7fffffff,ffffffff |
| h. | Prints: fffffffe,7fffffff,7fffffff |
| i. | Run-time error |
| j. | Compile-time error |
| k. | None of the above |
class EBH201 {
public static void main (String[] args) {
int a = 1 || 2 ^ 3 && 5;
int b = ((1 || 2) ^ 3) && 5;
int c = 1 || (2 ^ (3 && 5));
System.out.print(a + "," + b + "," + c);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 0,0,0 |
| b. | Prints: 0,0,3 |
| c. | Prints: 0,3,0 |
| d. | Prints: 0,3,3 |
| e. | Prints: 3,0,0 |
| f. | Prints: 3,0,3 |
| g. | Prints: 3,3,0 |
| h. | Prints: 3,3,3 |
| i. | Run-time error |
| j. | Compile-time error |
| k. | None of the above |
class EBH202 {
static boolean a, b, c;
public static void main (String[] args) {
boolean x = (a = true) || (b = true) && (c = true);
System.out.print(a + "," + b + "," + c);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: false,false,false |
| b. | Prints: false,false,true |
| c. | Prints: false,true,false |
| d. | Prints: false,true,true |
| e. | Prints: true,false,false |
| f. | Prints: true,false,true |
| g. | Prints: true,true,false |
| h. | Prints: true,true,true |
| i. | Run-time error |
| j. | Compile-time error |
| k. | None of the above |
class EBH203 {
static boolean a, b, c;
public static void main (String[] args) {
boolean x = a || (b = true) && (c = true);
System.out.print(a + "," + b + "," + c);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: false,false,false |
| b. | Prints: false,false,true |
| c. | Prints: false,true,false |
| d. | Prints: false,true,true |
| e. | Prints: true,false,false |
| f. | Prints: true,false,true |
| g. | Prints: true,true,false |
| h. | Prints: true,true,true |
| i. | Run-time error |
| j. | Compile-time error |
| k. | None of the above |
class EBH011 {
public static void main (String[] args) {
float a = Float.POSITIVE_INFINITY;
double b = Double.POSITIVE_INFINITY;
double c = Double.NaN;
System.out.print((a == b)+","+(c == c)+","+(c != c));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: false,false,false |
| b. | Prints: false,false,true |
| c. | Prints: false,true,false |
| d. | Prints: false,true,true |
| e. | Prints: true,false,false |
| f. | Prints: true,false,true |
| g. | Prints: true,true,false |
| h. | Prints: true,true,true |
| i. | Run-time error |
| j. | Compile-time error |
| k. | None of the above |
class EBH012 {
public static void main (String[] args) {
byte x = 3, y = 5;
System.out.print((-x == ~x + 1)+","+(-y == ~y + 1));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: false,false |
| b. | Prints: false,true |
| c. | Prints: true,false |
| d. | Prints: true,true |
| e. | Run-time error |
| f. | Compile-time error |
| g. | None of the above |
class EBH013 {
public static void main (String[] args) {
byte x = 3, y = 5;
System.out.print((~x == -x - 1)+","+(~y == -y - 1));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: false,false |
| b. | Prints: false,true |
| c. | Prints: true,false |
| d. | Prints: true,true |
| e. | Run-time error |
| f. | Compile-time error |
| g. | None of the above |
class EBH014 {
public static void main (String[] args) {
byte x = 3, y = 5;
System.out.print((y % x) + ",");
System.out.print(y == ((y/x)*x + (y%x)));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 1,true |
| b. | Prints: 2,true |
| c. | Prints: 1,false |
| d. | Prints: 2,false |
| e. | Run-time error |
| f. | Compile-time error |
| g. | None of the above |
class Color {}
class Red extends Color {}
class Blue extends Color {}
class A {
public static void main (String[] args) {
Color color1 = new Red(); Red color2 = new Red();
boolean b1 = color1 instanceof Color;
boolean b2 = color1 instanceof Blue;
boolean b3 = color2 instanceof Blue;
System.out.print(b1+","+b2+","+b3);
}}
What is the result of attempting to compile and run the program?
| a. | false,false,false |
| b. | false,false,true |
| c. | false,true,false |
| d. | false,true,true |
| e. | true,false,false |
| f. | true,false,true |
| g. | true,true,false |
| h. | true,true,true |
| i. | Run-time error |
| j. | Compile-time error |
| k. | None of the above |
class EBH020 {
public static void main (String[] args) {
int a = 1 | 2 ^ 3 & 5;
int b = ((1 | 2) ^ 3) & 5;
int c = 1 | (2 ^ (3 & 5));
System.out.print(a + "," + b + "," + c);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 0,0,0 |
| b. | Prints: 0,0,3 |
| c. | Prints: 0,3,0 |
| d. | Prints: 0,3,3 |
| e. | Prints: 3,0,0 |
| f. | Prints: 3,0,3 |
| g. | Prints: 3,3,0 |
| h. | Prints: 3,3,3 |
| i. | Run-time error |
| j. | Compile-time error |
| k. | None of the above |
class EBH025 {
public static void main (String args[]) {
int i1 = 0xffffffff, i2 = i1 << 33;
int i3 = i1 << (33 & 0x1f);
System.out.print(Integer.toHexString(i2) + ",");
System.out.print(Integer.toHexString(i3));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 0,0 |
| b. | Prints: 0,fffffffe |
| c. | Prints: 0,ffffffff |
| d. | Prints: ffffffff,ffffffff |
| e. | Prints: ffffffff,fffffffe |
| f. | Prints: fffffffe,ffffffff |
| g. | Prints: fffffffe,fffffffe |
| h. | Run-time error |
| i. | Compile-time error |
| j. | None of the above |
class EBH001 {
static int m(int i) {System.out.print(i + ", "); return i;}
public static void main(String s[]) {
m(m(1) - m(2) + m(3) * m(4));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 1, 2, 3, 4, 8, |
| b. | Prints: 1, 2, 3, 4, 11, |
| c. | Prints: 3, 4, 1, 2, 11, |
| d. | Run-time error |
| e. | Compile-time error |
| f. | None of the above |
class EBH002 {
static int m(int i) {System.out.print(i + ", "); return i;}
public static void main(String s[]) {
m(m(1) + m(2) % m(3) * m(4));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 1, 2, 3, 4, 0, |
| b. | Prints: 1, 2, 3, 4, 3, |
| c. | Prints: 1, 2, 3, 4, 9, |
| d. | Prints: 1, 2, 3, 4, 12, |
| e. | Prints: 2, 3, 4, 1, 9, |
| f. | Prints: 2, 3, 4, 1, 3, |
| g. | Run-time error |
| h. | Compile-time error |
| i. | None of the above |
class EBH005 {
public static void main (String[] s) {
byte b = 127; b <<= 2;System.out.println(b);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: -4 |
| b. | Prints: -3 |
| c. | Prints: -2 |
| d. | Prints: 0 |
| e. | Prints: 1 |
| f. | Prints: 127 |
| g. | Prints: 508 |
| h. | Run-time error |
| i. | Compile-time error |
| j. | None of the above |
class EBH007{
public static void main (String[] s) {
byte b = 5; System.out.println(b<<33);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: -1 |
| b. | Prints: 0 |
| c. | Prints: 1 |
| d. | Prints: 5 |
| e. | Prints: 10 |
| f. | Run-time error |
| g. | Compile-time error |
| h. | None of the above |
class EBH015 {
public static void main (String[] args) {
System.out.print((new Object() instanceof Object)+",");
System.out.print((new Object() instanceof String)+",");
System.out.print((new String() instanceof Object));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: false,false,false |
| b. | Prints: false,false,true |
| c. | Prints: false,true,false |
| d. | Prints: false,true,true |
| e. | Prints: true,false,false |
| f. | Prints: true,false,true |
| g. | Prints: true,true,false |
| h. | Prints: true,true,true |
| i. | Run-time error |
| j. | Compile-time error |
| k. | None of the above |
class EBH101 {
static int m(int i) {System.out.print(i + ", "); return i;}
public static void main(String s[]) {
int i = 1; m(m(++i) + m(i++) + m(-i) + m(i++));
}}
What is the result of attempting to compile and run the above program?
| a. | Prints: 1, 2, 3, 4, 10, |
| b. | Prints: 1, 2, -3, 4, 4, |
| c. | Prints: 2, 2, -3, -3, -2, |
| d. | Prints: 2, 2, -3, 3, 4, |
| e. | Prints: 2, 3, -3, -2, 0, |
| f. | Prints: 2, 3, -3, 4, 6, |
| g. | Prints: 2, 3, 4, 5, 14, |
| h. | Run-time error |
| i. | Compile-time error |
| j. | None of the above |
class EBH102 {
static int m(int i) {System.out.print(i + ","); return i;}
public static void main(String s[]) {
int i = 1, j = m(i++) + m(i++) * m(i++) + m(i++);
System.out.print(j % 5);
}}
What is the result of attempting to compile and run the above program?
| a. | Prints: 1,2,3,4,0 |
| b. | Prints: 1,2,3,4,1 |
| c. | Prints: 1,2,3,4,2 |
| d. | Prints: 1,2,3,4,3 |
| e. | Prints: 1,2,3,4,4 |
| f. | Prints: 1,2,3,4,5 |
| g. | Run-time error |
| h. | Compile-time error |
| i. | None of the above |
class EBH103 {
public static void main (String[] args) {
byte a = 1, b = 2, c = (byte)a++, d = (byte)++b, e = (byte)a + b;
System.out.print(c + d + e);
}}
What is the result of attempting to compile and run the above program?
| a. | Prints: 1 2 3 |
| b. | Prints: 6 |
| c. | Prints: 2 3 5 |
| d. | Prints: 10 |
| e. | Prints: 1 3 4 |
| f. | Prints: 8 |
| g. | Prints: 1 3 5 |
| h. | Prints: 9 |
| i. | Run-time error. |
| j. | Compile-time error. |
| k. | None of the above |
class EBH204 {
static boolean m1(String s, boolean b) {
System.out.print(s + (b ? "T" : "F"));
return b;
}
public static void main(String[] args) {
m1("A",m1("B",false) || m1("C",true) || m1("D",false));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: ATBFCT |
| b. | Prints: ATBFCTDF |
| c. | Prints: BFCTAT |
| d. | Prints: BTCTDFAT |
| e. | Run-time error |
| f. | Compile-time error |
| g. | None of the above |
class EBH104 {
static int m(int i) {System.out.print(i + ", "); return i;}
public static void main(String s[]) {
int i = 1; m(m(++i) - m(i++) + m(-i) * m(~i));
}}
What is the result of attempting to compile and run the above program?
| a. | Prints: 2, 2, -3, -4, 8, |
| b. | Prints: 2, 2, -3, -4, 12, |
| c. | Prints: 2, 3, -3, -4, 7, |
| d. | Prints: 1, 1, 1, 1, 0, |
| e. | Prints: 2, 2, -2, -2, 4, |
| f. | Prints: 2, 3, -2, -2, 3, |
| g. | Prints: -1, -2, 2, 2, 0, |
| h. | Run-time error |
| i. | Compile-time error |
| j. | None of the above |
class EBH105 {
static int m(int i) {System.out.print(i + ","); return 0;}
public static void main (String[] args) {
int i = 0; i = i++ + m(i); System.out.print(i);
}}
What is the result of attempting to compile and run the above program?
| a. | Prints: 0,0 |
| b. | Prints: 1,0 |
| c. | Prints: 0,1 |
| d. | Prints: 1,1 |
| e. | Run-time error |
| f. | Compile-time error |
| g. | None of the above |
class EBH106 {
public static void main(String args[]) {
int a = 1; a += ++a + a++; System.out.print(a);
}}
What is the result of attempting to compile and run the above program?
| a. | Prints: 3 |
| b. | Prints: 4 |
| c. | Prints: 5 |
| d. | Prints: 6 |
| e. | Prints: 7 |
| f. | Run-time error |
| g. | Compile-time error |
| h. | None of the above |
class EBH107 {
static int m(int i) {System.out.print(i + ","); return i;}
public static void main(String s[]) {
int i=0, j = m(++i) + m(++i) * m(++i) % m(++i) + m(++i);
System.out.print(j%5);
}}
What is the result of attempting to compile and run the above program?
| a. | Prints: 1,2,3,4,5,0 |
| b. | Prints: 1,2,3,4,5,1 |
| c. | Prints: 1,2,3,4,5,2 |
| d. | Prints: 1,2,3,4,5,3 |
| e. | Prints: 1,2,3,4,5,4 |
| f. | Prints: 1,2,3,4,5,5 |
| g. | Run-time error |
| h. | Compile-time error |
| i. | None of the above |
class EBH108 {
public static void main(String s[]) {
int i=0, j = ++i + ((++i * ++i) % ++i) + ++i;
System.out.print(j%5);
}}
What is the result of attempting to compile and run the above program?
| a. | Prints: 1 |
| b. | Prints: 2 |
| c. | Prints: 3 |
| d. | Prints: 4 |
| e. | Prints: 5 |
| f. | Run-time error |
| g. | Compile-time error |
| h. | None of the above |
class EBH023 {
static String m1(boolean b){return b?"T":"F";}
public static void main(String [] args) {
boolean b1 = false?false:true?false:true?false:true;
boolean b2 = false?false:(true?false:(true?false:true));
boolean b3 = ((false?false:true)?false:true)?false:true;
System.out.println(m1(b1) + m1(b2) + m1(b3));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: FFF |
| b. | Prints: FFT |
| c. | Prints: FTF |
| d. | Prints: FTT |
| e. | Prints: TFF |
| f. | Prints: TFT |
| g. | Prints: TTF |
| h. | Prints: TTT |
| i. | Run-time error |
| j. | Compile-time error |
| k. | None of the above |
class EBH024 {
public static void main(String[] args) {
int i1 = 15;
String b1 = (i1>30)?"Red":(i1>20)?"Green":(i1>10)?"Blue":"Violet";
String b2 = (i1>30)?"Red":((i1>20)?"Green":((i1>10)?"Blue":"Violet"));
System.out.println(b1 + "," + b2);
}}
What is the result of attempting to compile and run the program?
| a. | Prints: Red,Red |
| b. | Prints: Green,Green |
| c. | Prints: Blue,Blue |
| d. | Prints: Violet,Violet |
| e. | Prints: Blue,Violet |
| f. | Prints: Violet,Blue |
| g. | Prints: Blue,Green |
| h. | Prints: Green,Blue |
| i. | Run-time error |
| j. | Compile-time error |
| k. | None of the above |
class EBH003 {
static int m(int i) {System.out.print(i + ", "); return i;}
public static void main(String s[]) {
m(m(~1) + m(1|2) + m(1&2) + m(1^3) + m(1<<1));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: -2, 3, 0, 3, 0, 6, |
| b. | Prints: -2, 3, 0, 2, 1, 4, |
| c. | Prints: -2, 3, 0, 2, 2, 5, |
| d. | Prints: -2, 3, 0, 3, 2, 6, |
| e. | Prints: -1, 3, 0, 3, 2, 7, |
| f. | Prints: -2, 0, 3, 3, 0, 6, |
| g. | Prints: -1, 0, 3, 2, 1, 4, |
| h. | Prints: -2, 0, 3, 2, 2, 5, |
| i. | Prints: -2, 0, 3, 3, 2, 6, |
| j. | Prints: -1, 0, 3, 3, 2, 7, |
| k. | Run-time error |
| l. | Compile-time error |
| m. | None of the above |
class EBH021 {
public static void main(String[] args) {
System.out.print((-1 & 0x1f) + "," + (8 << -1));
}}
What is the result of attempting to compile and run the program?
| a. | Prints: 0,0 |
| b. | Prints: -1,4 |
| c. | Prints: 0x1f,8 |
| d. | Prints: 31,16 |
| e. | Run-time error |
| f. | Compile-time error |
| g. | None of the above |