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. Q1) Sample Code import java.awt.*;

class A extends Frame implements ActionListener, WindowListener { public A() { Button button1 = new Button("Click Me"); button.addActionListener(this); add(button1); show(); } 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) (b) (c) (d) (e)
if e.getActionCommand().equals("button1")) b1(); if e.type == ButtonAction) b1(); if (e.getSource().equals(button1)) b1(); b1(); if e.target == button1) b1

Q2) Each method represents a stage in the life of a java applet EXCEPT which one of the following? (a) (b) (c) (d) (e) stop() show() destroy() init() start()

Q3) 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 { --y; } return y; }

Referring to the above, what value is returned when method func(4) is invoked? (a) (b) (c) (d) (e) -2 -1 0 1 2

Q4) Sample Code int count = 0;

while (count < 12) { count++; }

What code is equivalent to the code above? (a) (b) (c) (d) (e)
for(int count<12;count==0; ) { count++; } for(count<12;count=0;count++) { } for(int count=0;count<12;count++) { count++; } for(int count=0;count<12;count++) {} for(int count;count<12;count=0) { count++; }

Q5) Widget

Choice A

The widget shown above is similar to which standard java.awt class? (a) (b) (c) (d) (e) List PullMenu Select Choice Menu

Q6) Sample Code SecurityManager sm = System.getSecurityManager();
if(sm != null) { sm.checkRead("filename.txt"); }

When an untrusted application executes the code above, what happens if the SecurityManager object is set up to deny this resource? (a) (b) (c) (d) (e) The SecurityManager will stop the read when read method calls are invoked. checkRead() will return false The SecurityManager will cause the java virtual machine to exit. The SecurityManager will terminate the thread attempting to read the file. checkRead() will throw a java.security.SecurityException

Q7) 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) (b) (c) (d) (e) 0 1 3 4 6

Q8) 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 code?
(a)c = new Connection("sun.jdbc.odbc.JdbcOdbcDriver:Fred", "ellen", "password"); (b)Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); c = new Connection("sun.jdbc.odbc.JdbcOdbcDriver","Fred"); c.login( "ellen", "password" ); (c)Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); 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");

Q9) 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) (b) (c) (d) (e)
value += flag; if(value) i++; value = ++i; if(value.equals( str )) System.out.println(str); value = str;

Q10) 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) (b) (c) (d) (e) 0 10 17 null The compiler will error because of duplicate method names

Q11) Which statement expresses a value that CANNOT be modified? (a) (b) (c) (d) (e)
public static public static public static final int ANSWER_TO_ULTIMATE_QUESTION = 42; volatile int ANSWER_TO_ULTIMATE_QUESTION = 42; static native long ANSWER_TO_ULTIMATE_QUESTION = 42L; int ANSWER_TO_ULTIMATE_QUESTION = 42; transient int ANSWER_TO_ULTIMATE_QUESTION = 42;

Q12) 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) (b) (c) (d) (e) Override variable myCount Declare static versions of method1() and method2() Be in the same package as A Be abstract Include non-abstract versions of method1() and method2()

Q13) When do you override the finalize() method? (a) (b) (c) (d) (e) When you want to kill a thread When you must ensure that memory allocated to an object is released When you instantiate a "final" class When th ere is cleanup activity needed before an object is destroyed When an object is no longer needed

Q14) Which one of the following declarations is NOT valid? (a) (b) (c) (d) (e)
char firstname[][]; int[] counts; char firstname[] = new char[15]; int[] counts = {2,3,5,7,8,14}; char[] answer[] = {"Yes", "No"};

Q15) Sample Code class A {

}

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

Referring to the above, which one of the following describes the method main()? (a) (b) (c) (d) (e) It is invoked by the system at start up. It is doIt()'s parent method. It is a method other objects must invoke before invoking other methods. It is the core method of the Applet. It is an arbitrary method.

Q16) 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) (b) (c) (d) (e) 0 1.0 2.0 2.33 7.0

Q17) 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) (b) (c) (d) (e) Classes in the same package Subclasses of A. Class A Superclasses of A in the same package All classes

Q18) What is Java serialization? (a) (b) (c) (d) (e) The ability to examine the encapsulated data of a class. Distributed persistence. Remote method invocation. Marshaling and unmarshaling of remote objects. The ability to read and write the state of an object

Q19) 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) (b) (c) (d) (e) Midnight The most recent whole minute Midnight GMT on January 1, 1988 Midnight GMT on January 1, 1970 The most recent even hour
int count=0, i=0; do { count += i; i++; if(count > 5) break; } while(i<=4);

Q20) Sample Code

Referring to the above, what is the value of "count" after execution? (a) (b) (c) (d) (e) 0 1 4 6 10

Q21) 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) (b) (c) (d) (e) Improper class definition Inner class Nested class declaration Superclass of A Subclass of A

Q22) Sample Code int count=0;

for(int i=0; i<10; i++) count++;

Referring to the above, what is the value of "count" after execution? (a) (b) (c) (d) (e) 0 1 9 10 11

Q23) 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) (b) (c) (d) (e)
catch( MyException e) { } exception new MyException(); MyException e = new MyException(); return e; throw new MyException("Error Occurred!"); new Exception( MyException );

Q24) Sample Code if (check4Biz(storeNum) < 10) {} Referring to the above, what datatype could be returned by method check4Biz()? (a) (b) (c) (d) (e) int Boolean char[] String java.util.Bitset

Q25) Sample Code int x=3, y=5, z=2;
if(x <= y) { x += z; if(z != x) y = (x - z)/y; z++; } else if (y == 0) { y++; z *= y; } else y = 10;

Referring to the above, what are the values of x, y, and z after executing the sample code? (a) (b) (c) (d) (e) x=5, y=0, z=3 x=3, y=10, z=2 x=6, y=0, z=3 x=3, y=6, z=3 x=5, y=5, z=3

Q26) What type of variable can be changed at runtime but is always the same for all objects of a given class? (a) (b) (c) (d) (e) Final Static Public protected Char Int

Q27) What class creates a listening TCP connection? (a) (b) (c) (d) (e) java.net.ServerSocket java.net.DatagramSocket java.net.InputSocket java.net.ListeningSocket java.net.URLConnection

Q28) 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) (b) (c) (d) (e) 2 4.2 6 7 7.5

Q29) 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() threadsafe? (a) (b) (c) (d) (e) Implement the "java.lang.singleThreaded" interface Declare increment() synchronized Declare increment() as static final Declare Counter synchronized Modify increment() to make all other threads unrunnable state until the method is completed

Q30) 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; System.out.println(x); System.out.println(y); }

}

Referring to the above, what is the output? (a) 0 8 (b) 10 3 (c) 10 0 (d) 5 8 (e) 10 8 Q31) Sample Code import java.sql.*;

// Insert additional code here Connection con = DriverManager.getConnection(url); String s = "call proc(?,?,?,?)"; CallableStatement cs = con.prepareCall(s); cs.setInt(1,1); cs.setInt(2,2); cs.setInt(3,3); cs.registerOutParameter(4,java.sql.TYPES.INTEGER);

Referring to the above, which of the following commands executes procedure proc(), which includes two INSERT SQL statements and one OUT parameter? (a) (b) (c) (d) (e) cs.executeQuery() con.getConnection(cs) cs.prepareCall().execute() ResultSet = cs.runQuery() cs.execute()

Q32) 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) (b) (c) (d) Throw a NoSuchClassError and not load the applet The browser will reject the entire web page and revert to the previous page Pop open a window asking permission to load a class from an untrusted source Throw a NoSuchClassException, alert the user, ignore the missing methods, and continue (e) Request the needed class file from the web server Q33) Which class CANNOT be directly instantiated? (a) (b) (c) (d) (e) java.io.BufferedReader java.io.DataInputStream java.io.FileReader java.io.InputStream java.io.StringBufferInputStream

Q34) Which one of the following about a "persistent" object is true? (a) (b) (c) (d) (e) It is referenced by a daemon thread. It is stored in a relational database instead of ram. It uses connection-oriented TCP packets for communication. It exists beyond the life of the program that created it. It cannot be garbage collected

Q35) Sample Code class Class1 {

public static void main(String args[]) { int i = 0, total = 0; while(i<4) { i++; if (i > 2) break; total += i; } System.out.println(total); }

}

What is the output of the program above? (a) (b) (c) (d) (e) 0 1 2 3 6

Q36) 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) (b) (c) (d) (e) -2 -1 0 1 2

Q37) 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) (b) (c) (d) (e) Implement Threadable Instantiate a new Thread Subclass ThreadGroup Make the class public, implement Runnable, and add a main() method Implement Runnable and add a "public void run()" method

Q38) Sample Code public abstract class A

extends B, C implements D, E { /*...*/ }

Referring to the above, what is WRONG with the class declaration? (a) (b) (c) (d) (e) Abstract classes cannot inherit. Public classes cannot implement interfaces. Classes can only inherit from other classes in the same package. Classes can only implement one interface. Classes can only derive directly from one other class.

Sign up to vote on this title
UsefulNot useful