Java Certification Mock Exam
John Hunt
Email: jjh@aber.ac.uk
URL: //www.aber.ac.uk/~jjh/Java
As with any examination technique is an important aspect of the examination process. In most situations there are mock examinations that you can use to obtain experience. This is the intention of this Java Certification Mock Exam.
This mock exam is solely intended to help those intending to take Sun’s Certified Java Programmer 1.1. examination practice the style of questions used in the examination. It should not be used as a way of learning Java nor should it be treated as a form of revision.
Note some care has been taken to ensure that the style of questions are the same as those in the actual exam, but that no questions from the examination are actually included. The style is based on one persons experience of taking the Java Certification examination and it should therefore not be assumed that this mock exam is an exact reflection of the actual exam.
This mock examination consists of 65 questions (the actual exam consists of 60 questions).
Just as in the actual examination a mixture of style of questions are included. These range between questions that require a single answer and those that require 1 or more answers. The former are indicated by:
The latter by:
Note a question that has the above request may require only one option, it is for you to decide. However, if you do not identify all the options for that question, then you will score zero for that question. One free format question is included as an example of that style of questioning.
As in the actual exam you should not attempt to identify any trends relating to As, Bs or Cs. That is, do not assume that because the answer A has not appeared for a while there is a good chance that it will soon.
For the actual examination the pass mark is 70% you should therefore aim to achieve at least 46 correct answers in this mock examination.
The correct answers are give at the end of the examination.
Disclaimer: This mock examination is in no way sanctioned by Sun Microsystems and no guarantees are provided about the similarity of these questions to those in the actual exam.
Q. 1
Which colour is used to indicate instance methods in the standard "javadoc" format documentation:
Select the most appropriate answer.
Q. 2
What is the correct ordering for the import, class and package declarations when found in a single file?
Select the most appropriate answer.
Q. 3
Which methods can be legally applied to a string object?
Select all correct answers.
Q. 4
What is the parameter specification for the public static void main method?
Select all correct answers.
Q. 5
What does the zeroth element of the string array passed to the public static void main method contain?
Select the most appropriate answer.
Q. 6
Which of the following are Java keywords?
Select all correct answers
Q. 7
What will be the result of compiling the following code:
public class Test {
public static void main (String args []) {
int age;
age = age + 1;
System.out.println("The age is " + age);
}
}
Select the most appropriate answer.
Q. 8
Which of these is the correct format to use to create the literal char value a?
Select the most appropriate answer.
Q. 9
What is the legal range of a byte integral type?
Select the most appropriate answer.
Q. 10
Which of the following is illegal:
Select the most appropriate answer.
Q. 11
What will be the result of compiling the following code:
public class Test {
static int age;
public static void main (String args []) {
age = age + 1;
System.out.println("The age is " + age);
}
}
Select the most appropriate answer.
Q. 12
Which of the following are correct?
Select all correct answers
Q. 13
Which of the following return true?
Select all correct answers.
Q. 14
Which of the following do not lead to a runtime error?
Select all correct answers.
Q. 15
Which of the following are so called "short circuit" logical operators?
Select all correct answers.
Q. 16
Which of the following are acceptable?
Select all correct answers.
Q. 17
What is the result of compiling and running the following code:
public class Test {
static int total = 10;
public static void main (String args []) {
new Test();
}
public Test () {
System.out.println("In test");
System.out.println(this);
int temp = this.total;
if (temp > 5) {
System.out.println(temp);
}
}
}
Select all correct answers.
Q 18
Which of the following is correct:
Select the most appropriate answer.
Q. 19
What is the correct declaration of an abstract method that is intended to be public:
Select the most appropriate answer.
Q. 20
Under what situations do you obtain a default constructor?
Select the most appropriate answer.
Q. 21
Given the following code:
public class Test {
…
}
Which of the following can be used to define a constructor for this class:
Select the most appropriate answer.
Q. 22
Which of the following are acceptable to the Java compiler:
Select all correct answers.
Q. 23
Assuming a method contains code which may raise an Exception (but not a RuntimeException), what is the correct way for a method to indicate that it expects the caller to handle that exception:
Select the most appropriate answer.
Q. 24
What is the result of executing the following code, using the parameters 4 and 0:
public void divide(int a, int b) {
try {
int c = a / b;
} catch (Exception e) {
System.out.print("Exception ");
} finally {
System.out.println("Finally");
}
Select the most appropriate answer.
Q.25
Which of the following is a legal return type of a method overloading the following method:
public void add(int a) {…}
Select the most appropriate answer.
Q.26
Which of the following statements is correct for a method which is overriding the following method:
public void add(int a) {…}
Select the most appropriate answer.
Q. 27
Given the following classes defined in separate files:
class Vehicle {
public void drive() {
System.out.println("Vehicle: drive");
}
}
class Car extends Vehicle {
public void drive() {
System.out.println("Car: drive");
}
}
public class Test {
public static void main (String args []) {
Vehicle v;
Car c;
v = new Vehicle();
c = new Car();
v.drive();
c.drive();
v = c;
v.drive();
}
}
What will be the effect of compiling and running this class Test?
Vehicle: drive
Car: drive
Car: drive
Vehicle: drive
Car: drive
Vehicle: drive
Select the most appropriate answer.
Q. 28
Where in a constructor, can you place a call to a constructor defined in the super class?
Select the most appropriate answer.
Q. 29
Which variables can an inner class access from the class which encapsulates it?
Select all correct answers.
Q. 30
What class must an inner class extend:
Select the most appropriate answer.
Q. 31
In the following code, which is the earliest statement, where the object originally held in
e, may be garbage collected:
Select the most appropriate answer.
Q. 32
What is the name of the interface that can be used to define a class that can execute within its own thread?
Select the most appropriate answer.
Q. 33
What is the name of the method used to schedule a thread for execution?
Select the most appropriate answer.
Q. 34
Which methods may cause a thread to stop executing?
Select all correct answers.
Q. 35
Write code to create a text field able to display 10 characters (assuming a fixed size font) displaying the initial string "hello":
:
Q. 36
Which of the following methods are defined on the Graphics class:
Select all correct answers.
Q. 37
Which of the following layout managers honours the preferred size of a component:
Select all correct answers.
Q. 38
Given the following code what is the effect of
a being 5:
public class Test {
public void add(int a) {
loop: for (int i = 1; i < 3; i++){
for (int j = 1; j < 3; j++) {
if (a == 5) {
break loop;
}
System.out.println(i * j);
}
}
}
}
Select the most appropriate answer.
Q. 39
What is the effect of issuing a wait() method on an object
Select the most appropriate answer.
Q. 40
The layout of a container can be altered using which of the following methods:
Select all correct answers.
Q. 41
Using a FlowLayout manager, which is the correct way to add elements to a container:
Select the most appropriate answer.
Q. 42
Given that a Button can generate an ActionEvent which listener would you expect to have to implement, in a class which would handle this event?
Select the most appropriate answer.
Q. 43
Which of the following, are valid return types, for listener methods:
Select the most appropriate answer.
Q. 44
Assuming we have a class which implements the ActionListener interface, which method should be used to register this with a Button?
Select the most appropriate answer.
Q. 45
In order to cause the paint(Graphics) method to execute, which of the following is the most appropriate method to call:
Select the most appropriate answer.
Q. 46
Which of the following illustrates the correct way to pass a parameter into an applet:
Select the most appropriate answer.
Q. 47
Which of the following correctly illustrate how an
InputStreamReader can be created:Select all correct answers.
Q. 48
What is the permanent effect on the file system of writing data to a new FileWriter("report"), given the file report already exists?
Select the most appropriate answer.
Q. 49
What is the effect of adding the sixth element to a vector created in the following manner:
new Vector(5, 10);
Select the most appropriate answer.
Q. 50
What is the result of executing the following code when the value of x is 2:
switch (x) {
case 1:
System.out.println(1);
case 2:
case 3:
System.out.println(3);
case 4:
System.out.println(4);
}
Select the most appropriate answer.
Q. 51
Consider the following example:
class First {
public First (String s) {
System.out.println(s);
}
}
public class Second extends First {
public static void main(String args []) {
new Second();
}
}
What is the result of compiling and running the Second class?
Select the most appropriate answer.
Q. 52 What is the result of executing the following fragment of code:
boolean flag = false;
if (flag = true) {
System.out.println("true");
} else {
System.out.println("false");
}
Select the most appropriate answer.
Q. 53
Consider the following classes:
public class Test {
public static void test() {
this.print();
}
public static void print() {
System.out.println("Test");
}
public static void main(String args []) {
test();
}
}
What is the result of compiling and running this class?
Select all correct answers.
Q. 54
Examine the following class definition:
public class Test {
public static void test() {
print();
}
public static void print() {
System.out.println("Test");
}
public void print() {
System.out.println("Another Test");
}
}
What is the result of compiling this class:
Select the most appropriate answer.
Q. 55
What is the result of compiling and executing the following Java class:
public class ThreadTest extends Thread {
public void run() {
System.out.println("In run");
suspend();
resume();
System.out.println("Leaving run");
}
public static void main(String args []) {
(new ThreadTest()).start();
}
}
Select the most appropriate answer.
Q. 56
Given the following sequence of Java statements
Which of the following statements are true:
Select all correct answers.
Q. 57
What is the result of executing the following Java class:
import java.awt.*;
public class FrameTest extends Frame {
public FrameTest() {
add (new Button("First"));
add (new Button("Second"));
add (new Button("Third"));
pack();
setVisible(true);
}
public static void main(String args []) {
new FrameTest();
}
}
Select from the following options:
Select the most appropriate answer.
Q. 58
Consider the following tags and attributes of tags:
Which of the above can be used within the <APPLET> and </APPLET> tags?
Select all correct answers.
Q. 59
Which of the following is a legal way to construct a RandomAccessFile:
Select the most appropriate answer.
Q. 60
Carefully examine the following code:
public class StaticTest {
static {
System.out.println("Hi there");
}
public void print() {
System.out.println("Hello");
}
public static void main(String args []) {
StaticTest st1 = new StaticTest();
st1.print();
StaticTest st2 = new StaticTest();
st2.print();
}
}
When will the string "Hi there" be printed?
Select the most appropriate answer.
Q. 61
Consider the following program:
public class Test { public static void main (String args []) { boolean a = false; if (a = true)
System.out.println("Hello");
Else
System.out.println("Goodbye");
}
}
What is the result:
A. Program produces no output but terminates correctly.
B. Program does not terminate.
C. Prints out "Hello"
D. Prints out "Goodbye"
Select the most appropriate answer.
Q. 62
Examine the following code which includes an inner class:
public final class Test4 implements A {
class Inner {
void test() {
if (Test4.this.flag); {
sample();
}
}
}
private boolean flag = false;
public void sample() {
System.out.println("Sample");
}
public Test4() {
(new Inner()).test();
}
public static void main(String args []) {
new Test4();
}
}
What is the result:
A. Prints out "Sample"
B. Program produces no output but terminates correctly.
C. Program does not terminate.
D. The program will not compile
Select the most appropriate answer.
Q. 63
Carefully examine the following class:
public class Test5 { public static void main (String args []) { /* This is the start of a comment
if (true) {
Test5 = new test5();
System.out.println("Done the test");
}
/* This is another comment */
System.out.println ("The end");
}
}
What is the result:
A. Prints out "Done the test" and nothing else.
B. Program produces no output but terminates correctly.
C. Program does not terminate.
D. The program will not compile.
E. The program generates a runtime exception.
F. The program prints out "The end" and nothing else.
G. The program prints out "Done the test" and "The end"
Select the most appropriate answer.
Q. 64
The following code defines a simple applet:
import java.applet.Applet;
import java.awt.*;
public class Sample extends Applet {
private String text = "Hello World";
public void init() {
add(new Label(text));
}
public Sample (String string) {
text = string;
}
}
It is accessed form the following HTML page:
<html>
<title>Sample Applet</title>
<body>
<applet code="Sample.class" width=200 height=200></applet>
</body>
</html>
What is the result of compiling and running this applet:
A. Prints "Hello World".
B. Generates a runtime error.
C. Does nothing.
D. Generates a compile time error.
Select the most appropriate answer.
Q. 65
Examine the following code:
public class Calc {
public static void main (String args []) {
int total = 0;
for (int i = 0, j = 10; total > 30; ++i, --j) {
System.out.println(" i = " + i + " : j = " + j);
total += (i + j);
}
System.out.println("Total " + total);
}
}
Does this code:
A. Produce a runtime error
B. Produce a compile time error
C. Print out "Total 0"
D. Generate the following as output:
i = 0 : j = 10
i = 1 : j = 9
i = 2 : j = 8
Total 30
Please select the most appropriate answer.
Answers to Java Certification Mock Exam
1. B |
2. A |
3. A, B, C, E |
4. A, B |
5. C |
6. A, C |
7. D |
8. A |
9. B |
10. B |
11. B |
12. A,B |
13. A, B |
14. A, B, C, D |
15.B, C |
16. A, E |
17. D |
18. D |
19. A |
20. B |
21. B |
22. A, C, D, E |
23. B |
24. A |
25. C |
26. A |
27. C |
28. B |
29. A, B, C |
30. C |
31. C |
32. A |
33. B |
34. A, B, C, D |
35. new TextField("hello", 10) |
36. A, B, C |
37. B |
38. D |
39. B |
40. A |
41. A |
42. D |
43. C |
44. B |
45. B |
46. B |
47. A, E |
48. B |
49. C |
50. C |
51. F |
52. A |
53. F |
54. C |
55. D |
56. D, F |
57. F |
58. A, E |
59. A |
60. C |
61. C |
62. A |
63. F |
64. B |
65. C |
Further Reading
Some useful references for the Java certification exam provided by Sun Microsystems are:
The Sun Educational Servcies web pages: http:/www.sun.com/service/suned/cert/.
For some on-line sample questions see: http:/www.sun.com/service/suned/cert/scjp11_quest.html.
In addition there are two books available which are aimed specifically at helping you to pass the Certification exam. These are:
Java 1.1 Certification Study Guide, Simon Roberts and Philip Heller, Sybex, ISBN 0-7821-2069-5, 1997. On-line information can be found at http://www.sybex.com/cgi-bin/bookpg.pl?2069back.html.
Java certification for programmers and developers, Barry Boone, McGraw-Hill, 0-0791-3657-5, 1997. On-line information can be found at http://mcgraw-hill.inforonics.com/cgi/getarec?mgh31641.
8th May 1998