Dan Chisholm's
Java Programmer Certification Mock Exam

Please Help Save a Tree!

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.


Question 1

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

Question 2

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

Question 3

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

Question 4

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

Question 5

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

Question 6

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

Question 7

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

Question 8

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


Copyright © 2002-2004, Dan Chisholm
All rights reserved.