Vous êtes sur la page 1sur 15

Some questions include additional information needed to answer them, such as sample

code or variable definitions. This information will be provided in a formatted section just
above the question.

Sample Code import java.awt.*;
class A extends Frame
implements ActionListener, WindowListener
public A()
Button button1 = new Button("Click Me");
public actionPerformed(ActionEvent e) {}
void b1() { return; }

Referring to the above, what statement should be added to actionPerformed() so that b1()
is invoked for a click on button1?

(a) if e.getActionCommand().equals("button1")) b1();

(b) if e.type == ButtonAction) b1();
(c) if (e.getSource().equals(button1)) b1();
(d) b1();
(e) if e.target == button1) b1

Each method represents a stage in the life of a java applet EXCEPT which one of the

(a) stop()
(b) show()
(c) destroy()
(d) init()
(e) start()
Sample Code public double SquareRoot( double value )
throws ArithmeticException
if (value >= 0) return Math.sqrt( value );
else throw new ArithmeticException();

public double func(int x)

double y = (double) x;
try {
y = SquareRoot( y );
catch(ArithmeticException e) {
y = 0;
finally {
return y;

Referring to the above, what value is returned when method func(4) is invoked?

(a) -2
(b) -1
(c) 0
(d) 1
(e) 2

Sample Code int count = 0;
while (count < 12) {

What code is equivalent to the code above?

(a) for(int count<12;count==0; ) { count++; }

(b) for(count<12;count=0;count++) { }
(c) for(int count=0;count<12;count++) { count++; }
(d) for(int count=0;count<12;count++) {}
(e) for(int count;count<12;count=0) { count++; }
Widget Choice A

The widget shown above is similar to which standard java.awt class?

(a) List
(b) PullMenu
(c) Select
(d) Choice
(e) Menu

Sample Code SecurityManager sm = System.getSecurityManager();
if(sm != null) {

When an untrusted application executes the code above, what happens if the
SecurityManager object is set up to deny this resource?

(a) The SecurityManager will stop the read when read method calls are invoked.
(b) checkRead() will return false
(c) The SecurityManager will cause the java virtual machine to exit.
(d) The SecurityManager will terminate the thread attempting to read the file.
(e) checkRead() will throw a java.security.SecurityException

Sample Code int count = 0;
for(int i = 0,j = 0; i<4; i++,j++)
count += j;

Referring to the above, what is the value of "count" after execution?

(a) 0
(b) 1
(c) 3
(d) 4
(e) 6
Sample Code import java.sql.*;
class query {
public static void main(String args[]) {
String str = "Select lname,salary from employee" +
" order by salary desc";
Connection c;
// Insert database initialization code here
Statement s = c.createStatement();
ResultSet rs = s.executeQuery(str);

Which of the code segments below would initialize the database connection in the above

(a)c = new Connection("sun.jdbc.odbc.JdbcOdbcDriver:Fred",

"ellen", "password");

c = new Connection("sun.jdbc.odbc.JdbcOdbcDriver","Fred");
c.login( "ellen", "password" );

String url = "jdbc:odbc:Fred";
c = DriverManager.getConnection(url, "ellen", "password");

(d)c = DriverManager.getConnection(
"sun.jdbc.odbc.JdbcOdbcDriver", "Fred");

(e)c = DriverManager.getConnection(
"sun.jdbc.odbc.JdbcOdbcDriver", "Fred");
c.login( "ellen", "password");

Sample Code int i = 0;
double value = 1.2;
String str = new String("1.2");
Boolean flag = true;

Which is a valid use of variable "value" as shown above?

(a) value += flag;

(b) if(value) i++;
(c) value = ++i;
(d) if(value.equals( str )) System.out.println(str);
(e) value = str;
Sample Code class A {
int getIt(int i) {
return 5 + 4*i;
class B extends A {
int getIt(int i) {
return 4 + 2*i;

Referring to the above, if a program instantiates a B object and invokes getIt() with a
parameter of 3, what value is returned?

(a) 0
(b) 10
(c) 17
(d) null
(e) The compiler will error because of duplicate method names

Which statement expresses a value that CANNOT be modified?

(a) public static final int ANSWER_TO_ULTIMATE_QUESTION = 42;

(b) static volatile int ANSWER_TO_ULTIMATE_QUESTION = 42;
(c) public static native long ANSWER_TO_ULTIMATE_QUESTION = 42L;
(d) static int ANSWER_TO_ULTIMATE_QUESTION = 42;
(e) public transient int ANSWER_TO_ULTIMATE_QUESTION = 42;

Sample Code public interface A {
static final int myCount = 10;
abstract public void method1(int i);
abstract public int method2(float f);
-- New File --
class B implements A {

Referring to the above, in order to implement A, what must class B do?

(a) Override variable myCount

(b) Declare static versions of method1() and method2()
(c) Be in the same package as A
(d) Be abstract
(e) Include non-abstract versions of method1() and method2()
When do you override the finalize() method?

(a) When you want to kill a thread

(b) When you must ensure that memory allocated to an object is released
(c) When you instantiate a "final" class
(d) When th ere is cleanup activity needed before an object is destroyed
(e) When an object is no longer needed

Which one of the following declarations is NOT valid?

(a) char firstname[][];

(b) int[] counts;
(c) char firstname[] = new char[15];
(d) int[] counts = {2,3,5,7,8,14};
(e) char[] answer[] = {"Yes", "No"};

Sample Code class A {
int i = 5;
public static void main(String args[]) {
A h = new A();
void doIt() {
i += 1;

Referring to the above, which one of the following describes the method main()?

(a) It is invoked by the system at start up.

(b) It is doIt()'s parent method.
(c) It is a method other objects must invoke before invoking other methods.
(d) It is the core method of the Applet.
(e) It is an arbitrary method.
Sample Code int h = 7;
float f = 3f;
float result = h%f;

Referring to the above, what is the value of "result" after execution?

(a) 0
(b) 1.0
(c) 2.0
(d) 2.33
(e) 7.0

Sample Code class A {
private int getIt(int i) {
return i*4;

Referring to the above, what classes can access method getIt() in class A?

(a) Classes in the same package

(b) Subclasses of A.
(c) Class A
(d) Superclasses of A in the same package
(e) All classes

What is Java serialization?

(a) The ability to examine the encapsulated data of a class.

(b) Distributed persistence.
(c) Remote method invocation.
(d) Marshaling and unmarshaling of remote objects.
(e) The ability to read and write the state of an object
Sample Code long time = System.currentTimeMillis();

Referring to the above, following execution, the value of variable time will be the number
of milliseconds since which one of the following?

(a) Midnight
(b) The most recent whole minute
(c) Midnight GMT on January 1, 1988
(d) Midnight GMT on January 1, 1970
(e) The most recent even hour

Sample Code int count=0, i=0;
do {
count += i;
if(count > 5) break;
} while(i<=4);

Referring to the above, what is the value of "count" after execution?

(a) 0
(b) 1
(c) 4
(d) 6
(e) 10

Sample Code class A {
int x = 2, y = 4, z = 7;
int calcW() { return x * y; }
class B {
int w = 9;
public int cvert(int i) { return calcW() * w; }

Referring to the above, class B is which one of the following?

(a) Improper class definition

(b) Inner class
(c) Nested class declaration
(d) Superclass of A
(e) Subclass of A
Sample Code int count=0;
for(int i=0; i<10; i++)

Referring to the above, what is the value of "count" after execution?

(a) 0
(b) 1
(c) 9
(d) 10
(e) 11

Sample Code package mypackage;
class MyException extends java.lang.Exception
public MyException() { super(); }
public MyException( String s ) { super(s); }

Referring to the above, which of the following code segments properly generates an
exception of type "MyException"?

(a) catch( MyException e) { }

(b) exception new MyException();
(c) MyException e = new MyException(); return e;
(d) throw new MyException("Error Occurred!");
(e) new Exception( MyException );

Sample Code if (check4Biz(storeNum) < 10) {}

Referring to the above, what datatype could be returned by method check4Biz()?

(a) int
(b) Boolean
(c) char[]
(d) String
(e) java.util.Bitset
Sample Code int x=3, y=5, z=2;
if(x <= y) {
x += z;
if(z != x)
y = (x - z)/y;
else if (y == 0) {
z *= y;
else y = 10;
Referring to the above, what are the values of x, y, and z after executing the sample code?

(a) x=5, y=0, z=3

(b) x=3, y=10, z=2
(c) x=6, y=0, z=3
(d) x=3, y=6, z=3
(e) x=5, y=5, z=3

What type of variable can be changed at runtime but is always the same for all objects of
a given class?

(a) Final
(b) Static
(c) Public protected
(d) Char
(e) Int

What class creates a listening TCP connection?

(a) java.net.ServerSocket
(b) java.net.DatagramSocket
(c) java.net.InputSocket
(d) java.net.ListeningSocket
(e) java.net.URLConnection
Sample Code float f = 5f;
float g = 2f;
float h;
h = 3+f/g+2;

Referring to the above, what is the final value of h?

(a) 2
(b) 4.2
(c) 6
(d) 7
(e) 7.5

Sample Code class Counter {
int count = 0;
int increment() {
int n = count;
count = n + 1;
return n;

Referring to the above, which of the following actions would make increment() thread-

(a) Implement the "java.lang.singleThreaded" interface

(b) Declare increment() synchronized
(c) Declare increment() as static final
(d) Declare Counter synchronized
(e) Modify increment() to make all other threads unrunnable state until the method is
Sample Code class A {
public static void main(String args[]) {
int i = 2;
int x = (i == 2) ? 5 : 10;
int y = (i == 5) ? 3 : 8;

Referring to the above, what is the output?

(a) 0
(b) 10
(c) 10
(d) 5
(e) 10

Sample Code import java.sql.*;
// Insert additional code here
Connection con = DriverManager.getConnection(url);
String s = "call proc(?,?,?,?)";
CallableStatement cs = con.prepareCall(s);

Referring to the above, which of the following commands executes procedure proc(),
which includes two INSERT SQL statements and one OUT parameter?

(a) cs.executeQuery()
(b) con.getConnection(cs)
(c) cs.prepareCall().execute()
(d) ResultSet = cs.runQuery()
(e) cs.execute()
Applet MyApplet includes custom class Class2. When the browser loads MyApplet.class
and CANNOT find Class2 locally, the browser will do which one of the following?

(a) Throw a NoSuchClassError and not load the applet

(b) The browser will reject the entire web page and revert to the previous page
(c) Pop open a window asking permission to load a class from an untrusted source
(d) Throw a NoSuchClassException, alert the user, ignore the missing methods, and
(e) Request the needed class file from the web server

Which class CANNOT be directly instantiated?

(a) java.io.BufferedReader
(b) java.io.DataInputStream
(c) java.io.FileReader
(d) java.io.InputStream
(e) java.io.StringBufferInputStream

Which one of the following about a "persistent" object is true?

(a) It is referenced by a daemon thread.

(b) It is stored in a relational database instead of ram.
(c) It uses connection-oriented TCP packets for communication.
(d) It exists beyond the life of the program that created it.
(e) It cannot be garbage collected
Sample Code class Class1 {
public static void main(String args[]) {
int i = 0, total = 0;
while(i<4) {
if (i > 2) break;
total += i;

What is the output of the program above?

(a) 0
(b) 1
(c) 2
(d) 3
(e) 6

Sample Code int x = 0, y = 0, z = 0;
x = 1;
x = (-x + y++) * ++z;

Referring to the above, what is the value of "x" after execution?

(a) -2
(b) -1
(c) 0
(d) 1
(e) 2
Sample Code class B extends A {
int xC, yC, k;
void move(int x) {
xC = x;

Referring to the above, to enable class B to be instantiated and executed in a separate

thread, which one of the following must you do?

(a) Implement Threadable

(b) Instantiate a new Thread
(c) Subclass ThreadGroup
(d) Make the class public, implement Runnable, and add a main() method
(e) Implement Runnable and add a "public void run()" method

Sample Code public abstract class A
extends B, C
implements D, E { /*...*/ }

Referring to the above, what is WRONG with the class declaration?

(a) Abstract classes cannot inherit.

(b) Public classes cannot implement interfaces.
(c) Classes can only inherit from other classes in the same package.
(d) Classes can only implement one interface.
(e) Classes can only derive directly from one other class.