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 Green {
  public static void main (String args[]) {
    int[] i = null;  // 1
    Cloneable c = i; // 2
    i = (int [])c;   // 3
}}

What is the result of attempting to compile and run the program?

a. Compile-time error at line 1.
b. Run-time error at line 1.
c. Compile-time error at line 2.
d. Run-time error at line 2.
e. Compile-time error at line 3.
f. Run-time error at line 3.
g. None of the above

Question 2

class Purple {
  public static void main (String []args) {
    int[] i = {1,2,3};  // 1
    Object obj = i;     // 2
    i = obj;            // 3
}}

What is the result of attempting to compile and run the program?

a. Compile-time error at line 1.
b. Run-time error at line 1.
c. Compile-time error at line 2.
d. Run-time error at line 2.
e. Compile-time error at line 3.
f. Run-time error at line 3.
g. None of the above

Question 3

import java.io.Serializable;
class Blue {
  public static void main (String args[]) {
    int[] i = {1,2,3};   // 1
    Serializable s = i;  // 2
    i = (int [])s;       // 3
}}

What is the result of attempting to compile and run the program?

a. Compile-time error at line 1.
b. Run-time error at line 1.
c. Compile-time error at line 2.
d. Run-time error at line 2.
e. Compile-time error at line 3.
f. Run-time error at line 3.
g. None of the above

Question 4

class Black {
  public static void main(String args[]) {
    int[] i = {1,2,3,4,5};                  // 1
    long[] l = new long[5];                 // 2
    for (int j = 0; j < l.length(); j++) {  // 3
      l[j] = i[j];                          // 4
}}}

A compile-time error is generated at which line?

a. 1
b. 2
c. 3
d. 4
e. None of the above

Question 5

class White {
  public static void main(String args[]) {
    int[] i = {1,2,3,4,5};     // 1
    long[] l1 = new long[5];   // 2
    long []l2 = l1;            // 3
    long l3[] = (long[])i;     // 4
    long l4[] = new long[5];   // 5
    l4[1] = i[1];              // 6
}}

A compile-time error is generated at which line?

a. 1
b. 2
c. 3
d. 4
e. 5
f. 6
g. None of the above

Question 6

class Amber {
  public static void main(String[] args) {
    int[][] a = {{1,2},{0,1,2},{-1,0,2}};  // 1
    Object[] obj = (Object[])a.clone();    // 2
    for(int i = 0; i < obj.length; i++) {  // 3
      int[] ia = (int[])obj[i];            // 4
      System.out.print(ia[i]);             // 5
}}}

A compile-time error is generated at which line?

a. 1
b. 2
c. 3
d. 4
e. 5
f. None of the above


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