|
Question Number 1
How can you store a copy of an object at the same time other threads may be changing the object's properties?
Choice 1
Override writeObject() in ObjectOutputStream to make it synchronized.
Choice 2
Clone the object in a block synchronized on the object and serialize the clone.
Choice 3
Nothing special, since all ObjectOutputStream methods are synchronized.
Choice 4
Implement java.io.Externalizable instead of java.io.Serializable.
Choice 5
Give the thread performing storage a higher priority than other threads.
------------------------------------------------------------
Question Number 2
Which statement about static inner classes is true?
Choice 1
Static inner classes may access any of the enclosing classes members.
Choice 2
Static inner classes may have only static methods.
Choice 3
Static inner classes may not be instantiated outside of the enclosing class.
Choice 4
Static inner classes do not have a reference to the enclosing class.
Choice 5
Static inner classes are created when the enclosing class is loaded.
------------------------------------------------------------
Question Number 3
public void createTempFiles(String d) {
File f = new File(d);
f.mkdirs();
// more code here ...
}
What is the result if the createTempFiles statement below is executed on the code above on a Unix platform?
if (System.getSecurityManager() == null)
createTempFiles( "/tmp/myfiles/_3214" );
Choice 1
A java.lang.SecurityException is thrown.
Choice 2
The file "_3214" is created in the "/tmp/myfiles" directory.
Choice 3
The "myfiles" directory is created in the "/tmp" directory.
Choice 4
A java.io.DirectoryNotCreatedException is thrown.
Choice 5
The directory "/tmp/myfiles/_3214" is created if it doesn't already exist.
------------------------------------------------------------
Question Number 4
Which one of the following is NOT a valid difference between java.awt.Canvas and Panel?
Choice 1
Canvas's can display images directly.
Choice 2
Panel can hold other components (including Canvas).
Choice 3
You can draw bit-oriented items (lines and circles) onto a Canvas.
Choice 4
Layout managers work with Panel objects.
Choice 5
Panel cannot be redrawn by a call to repaint().
------------------------------------------------------------
Question Number 5
The javadoc utility produces which one of the following?
Choice 1
A listing of key features of all classes and methods in the source document
Choice 2
An html document for each class, interface, or package
Choice 3
A document for each program that outlines flow, structure, inputs, and outputs
Choice 4
A listing of all classes and packages used by a program
Choice 5
A list of all qualified comment tags in a source document with the source code removed
------------------------------------------------------------
Question Number 6
int values[] = {1,2,3,4,5,6,7,8};
for(int i=0;i< X;)
System.out.println(values[i++]);
Referring to the above, what value for X will print all members of array "values"?
Choice 1
7
Choice 2
8
Choice 3
9
Choice 4
None, because the first value is never printed
Choice 5
None, since there is a syntax error in the array declaration
------------------------------------------------------------
Question Number 7
What causes an IllegalMonitorStateException?
Choice 1
A thread calls wait() or notify() before acquiring an object's monitor.
Choice 2
Two threads call a static synchronized method at the same time.
Choice 3
A thread invokes wait() on an object that is already waiting.
Choice 4
A thread invokes notify() on an object that is not waiting.
Choice 5
Two threads modify the same variable in the same object at the same moment.
------------------------------------------------------------
Question Number 8
double x=0;
x= (check().equals("1")) ? getSales() : nextStore();
What datatype could be returned by method check() as shown above?
Choice 1
int
Choice 2
boolean
Choice 3
Object
Choice 4
byte
Choice 5
char
------------------------------------------------------------
Question Number 9
1: class Class1 {
2: public static void main(String args[]) {
3: int total = 0;
4: int[] i = new int[3];
5: for(int j=1;j<= i.length; j++)
6: total += (i[j] = j);
7: System.out.println(total);
8: }
9: }
What is the output of the program above?
Choice 1
3
Choice 2
4
Choice 3
6
Choice 4
None. The system will throw an ArrayIndexOutOfBoundsException.
Choice 5
None. The compiler will throw a syntax error on line 6.
------------------------------------------------------------
Question Number 10
System.getProperties().put(
"java.rmi.server.codebase",
"http://www.domain.com/classes/");
Which one of the following is a capability of the above code?
Choice 1
Set the location of all applets in a web server
Choice 2
Append CLASSPATH
Choice 3
Register an rmi server on its host system
Choice 4
Facilitate dynamic class loading for remote objects
Choice 5
Override CLASSPATH
------------------------------------------------------------
Question Number 11
char ch1,ch2;
try { ch1 = (char) System.in.read(); }
catch(Exception e) {}
switch(ch1) {
case 'a':
ch2 = '1';
case 'b':
ch2 = '2';
case 'c':
ch2 = '3';
default:
ch2 = '4';
}
Referring to the above, during execution the user presses "b", what is the ending value of "ch2"?
Choice 1
'1'
Choice 2
'2'
Choice 3
'3'
Choice 4
'4'
Choice 5
null
------------------------------------------------------------
Question Number 12
Which java.sql class can return multiple result sets?
Choice 1
Statement
Choice 2
PreparedStatement
Choice 3
Any class derived from Statement that implements MultiResultSet
Choice 4
CallableStatement
Choice 5
ResultSet with the "multiple" property set to "true"
------------------------------------------------------------
Question Number 13
class A {
B b = new B();
C c = (C) b;
}
Referring to the above, when is the cast of "b" to class C allowed?
Choice 1
B and C are subclasses of the same superclass.
Choice 2
If B and C are superclasses of the same subclass.
Choice 3
C is a final class.
Choice 4
B is a subclass of C.
Choice 5
B is a superclass of C.
------------------------------------------------------------
Question Number 14
How can you have a "try" block that invokes methods that throw two different exceptions?
Choice 1
Catch one exception in a "catch" block and the other in a "finally" block.
Choice 2
Setup nested "catch" blocks for each exception.
Choice 3
Catch one exception in a "catch" block and the other via the return value.
Choice 4
Use wait() between the calls to process all exceptions before continuing.
Choice 5
Include a "catch" block for each exception.
------------------------------------------------------------
Question Number 15
static {
System.loadLibrary("mNativeLib");
}
public int myMethod(int count) {
Additional code here
}
Referring to the above, if myMethod() is implemented in native code library "mNativeLib", how must its declaration be changed?
Choice 1
Replace it with public System.nativeMethod("myMethod(int)");.
Choice 2
Replace myMethod()'s code with System.execute("mNativeLib", myMethod(count));.
Choice 3
Move it into the static code block.
Choice 4
Replace it with public native int myMethod(int count);.
Choice 5
Replace it with native myMethod(int count) {}.
------------------------------------------------------------
Question Number 16
Which one of the following is the equivalent of main() in a thread?
Choice 1
start()
Choice 2
go()
Choice 3
run()
Choice 4
begin()
Choice 5
The class constructor
------------------------------------------------------------
Question Number 17
What happens if a class defines a method with the same name and parameters as a method in its superclass?
Choice 1
The compiler automatically renames the subclass method.
Choice 2
The program runs since because overriding methods is allowed
Choice 3
The program throws a DuplicateMethod exception.
Choice 4
The subclass methods will be ignored.
Choice 5
The compiler shows a DuplicateMethod error.
------------------------------------------------------------
Question Number 18
class A {
static int getIt(int i) {
return i;
}
}
What is a consequence of "static" in the code above?
Choice 1
getIt() returns a static int
Choice 2
getIt() can only access static properties of class A
Choice 3
getIt() can be overridden
Choice 4
getIt() is invoked only by other static methods
Choice 5
Subclasses of class A must override method getIt()
------------------------------------------------------------
Question Number 19
1 public static void main(String[] s) {
2 String n1, n2, n3;
3 n1 = "n1";
4 n2 = "n2";
5 n3 = "n3";
6 {
7 String n4 = "inner";
8 n2 = n1;
9 }
10 n3 = null;
11 }
How many instances of the String will be eligible for garbage collection after line 10 in the above code snippet is executed?
Choice 1
0
Choice 2
1
Choice 3
2
Choice 4
3
Choice 5
The code will not compile.
------------------------------------------------------------
Question Number 20
try {
int values[] = {1,2,3,4,3,2,1};
for (int i = values.length-1; i >= 0; i++)
System.out.print( values[i] + " " );
} catch (Exception e) {
System.out.print("2" + " ");
} finally {
System.out.print("3" + " ");
}
What is the output of the program above?
Choice 1
1 2
Choice 2
1 3
Choice 3
1 2 3 4 3 2 1
Choice 4
1 2 3
Choice 5
1 2 3 4 3 2 1 3
------------------------------------------------------------
Question Number 21
native int computeAll();
Referring to the above, the keyword "native" indicates which one of the following?
Choice 1
That computeAll() is undefined and must be overridden
Choice 2
That computeAll() is an external method implemented in another language
Choice 3
That computeAll() is defined in the superclass
Choice 4
That the compiler must use file computeAll.java for platform-specific code
Choice 5
That computeAll() is an operating system command
------------------------------------------------------------
Question Number 22
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?
Choice 1
value = str;
Choice 2
if(value.equals( str )) System.out.println(str);
Choice 3
if(value) i++;
Choice 4
value += flag;
Choice 5
value = ++i;
------------------------------------------------------------
Question Number 23
class A implements Cloneable {
public int i, j, k;
String str = ("Hello There");
public Object clone() {
try {
return super.clone();
} catch (CloneNotSupportedException e) {}
}
}
class B extends A {
public B() {
i = 5;
j = 3;
k= -4;
}
}
Referring to the above, what will happen when the following code is executed?
B a = new B();
B b = (B) a.clone();
Choice 1
A CloneNotSupportedException is thrown.
Choice 2
Two identical class B objects are created.
Choice 3
One instance of class B is created with two pointers: "a" and "b".
Choice 4
Identical threads "a" and "b" are created.
Choice 5
Object "a" is instantiated and "b" is created as an inner class of "B".
------------------------------------------------------------
Question Number 24
What class represents the U.S. Mountain time zone in date/time calculations?
Choice 1
java.util.Locale
Choice 2
java.util.GregorianCalendar
Choice 3
java.util.Date
Choice 4
java.util.Calendar
Choice 5
java.util.SimpleTimeZone
------------------------------------------------------------
Question Number 25
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?
Choice 1
-2
Choice 2
-1
Choice 3
0
Choice 4
1
Choice 5
2
------------------------------------------------------------
Question Number 26
short tri[][] = new short[10][];
for(int i = 0,count =0 ; i < tri.length; i++ ) {
tri[i]= new short[i+1];
for(int j = 0 ; j < tri[i].length; j++ ) {
tri[i][j]= (short) count++;
}
}
At what array index does the array "tri" have the value 18 as shown above?
Choice 1
tri[3][3]
Choice 2
tri[4][4]
Choice 3
tri[5][3]
Choice 4
tri[6][2]
Choice 5
tri[4][5]
------------------------------------------------------------
Question Number 27
Which one of the following is NOT addressed by the java.security package?
Choice 1
Message digests
Choice 2
Access control lists
Choice 3
Cookies
Choice 4
Key management
Choice 5
Digital signatures
------------------------------------------------------------
Question Number 28
What concern is legitimate when overriding the java.lang.Object.finalize method?
Choice 1
The method must be thread safe.
Choice 2
The method may never execute.
Choice 3
The method must handle all exceptions.
Choice 4
The method must handle multiple concurrent invocations.
Choice 5
The method must ensure all object references are set to null.
------------------------------------------------------------
Question Number 29
Which one of the following is a limitation of subclassing the Thread class?
Choice 1
You must catch the ThreadDeath exception.
Choice 2
You must implement the Threadable interface.
Choice 3
You cannot have any static methods in the class.
Choice 4
You must declare the class final.
Choice 5
You cannot subclass any other class.
------------------------------------------------------------
Question Number 30
char ch1=' ';
int j = 0;
for(int i = 0 ; i < 5; i++) {
try { ch1 = (char) System.in.read(); }
catch(Exception e) {}
if (ch1 == 'a') break;
else if (ch1 == 'b') continue;
else if (ch1 == 'c') i--;
else if (ch1 == 'd') j++;
j++;
}
System.out.println( j );
What is the output during execution if the user types in "bdcda" as shown above?
Choice 1
2
Choice 2
3
Choice 3
4
Choice 4
5
Choice 5
6
------------------------------------------------------------
Question Number 31
1: import java.io.*;
2: class PrintThread extends Thread {
3: private static Object o = new Object();
4: private static DataOutputStream out = //... set to some output file
5: private int I;
6:
7: public PrintThread(int I) {
8: this.I = I;
9: }
10: public void run() {
11: while(true) {
12: try {
13: out.writeBytes("Hello all from thread " + I +"\r\n");
14: } catch (Exception e) {}
15: }
16: }
17: public static void main(String[] s) {
18: for (int i = 0; i < 5; i++ ) {
19: (new PrintThread(i)).start();
20: }
21: }
22: }
How could you ensure that each line of output from the above program came from an individual thread?
Choice 1
Make the run method "synchronized".
Choice 2
Insert the following code between line 11 and 12:
try {
sleep(100);
} catch(Exception e) {}
Choice 3
Add the "synchronized" modifier to the DataOuputStream "out" variable declaration.
Choice 4
Insert the following line between line 12 and 13:
synchronized(o) {
and this line between line 13 and 14
}
Choice 5
Insert the following code between line 11 and 12:
yield();
------------------------------------------------------------
Question Number 32
Which one of the following is a reason to double-buffer animations?
Choice 1
To draw each image to the screen twice to eliminate white spots
Choice 2
To use a small image as wallpaper and a transparent image as the actual frame
Choice 3
To put multiple frame in the same file and uses cropImage() to select the desired frame
Choice 4
To draw the next frame to an off-screen image object before displaying to eliminate flicker
Choice 5
To prevent "hanging" using a MediaTracker object to ensure all frames are loaded before beginning
------------------------------------------------------------
Question Number 33
String s1 = new String("AbraCadabra");
String s2 = new String(" willow woo");
String s3;
s3=s1.substring(1,5) + s2.toUpperCase().trim().substring(1,5);
Referring to the above, what is in s3 after execution?
Choice 1
braCaWILLO
Choice 2
braCILLO
Choice 3
braCWILL
Choice 4
braCaILLOW
Choice 5
AbraC WILL
------------------------------------------------------------
Question Number 34
class Class1 {
static int i=0;
public static void main(String args[]) {
for(int j=1;j<args.length;j+=2) {
i += Integer.parseInt(args[j]);
}
System.out.println(i);
}
}
What parameters could be passed on the command-line so that the output of the program above is "6"?
Choice 1
1 2 3 4
Choice 2
6 5 1
Choice 3
6
Choice 4
None. The system will throw an ArrayIndexOutOfBounds Exception.
Choice 5
None. The compiler will issue an error message because an exception must be caught when invoking parseInt().
------------------------------------------------------------
Question Number 35
What is the purpose of the java.text package?
Choice 1
To perform font management between different platforms
Choice 2
To provide classes for manipulating Strings
Choice 3
To allow formatting of text data for specific geographic locations
Choice 4
To facilitate spelling and grammar checks
Choice 5
To render text strings on java.awt.Container objects
------------------------------------------------------------
Question Number 36
Which class formats the exact time for a web page used by people in India?
Choice 1
java.util.GregorianCalendar
Choice 2
java.util.Time
Choice 3
java.text.TimeFormat
Choice 4
java.util.Date
Choice 5
java.text.SimpleDateFormat
------------------------------------------------------------
Question Number 37
Compared to connection-oriented sockets, which statement about connectionless sockets is true?
Choice 1
They support only character streams.
Choice 2
They do not support two-way communication.
Choice 3
They do not guarantee delivery or order of receipt.
Choice 4
They can transmit to multiple receivers at the same time.
Choice 5
They are less efficient and slower.
------------------------------------------------------------
Question Number 38
class MyButton extends Button {
private int pressCount=0;
private static Panel panel;
public MyButton(String txt) {
super( txt );
if (panel != null) panel=new Panel();
}
protected void finalize() throws Throwable {
panel.add( this );
System.out.println("GoodBye!");
}
}
What is WRONG with the code above?
Choice 1
Super class Button doesn't have a public constructor which takes a String as a parameter.
Choice 2
The finalize method must be declared public.
Choice 3
Accessing a static method inside the constructor call.
Choice 4
The paint() method is not overridden.
Choice 5
class MyButton cannot ever get garbage collected correctly.
------------------------------------------------------------
Question Number 39
_______________
| Choice A \/ |
The widget shown above is similar to which standard java.awt class?
Choice 1
Menu
Choice 2
PullMenu
Choice 3
List
Choice 4
Choice
Choice 5
Select
------------------------------------------------------------
Question Number 40
What class is subclassed to package several locale-specific versions of a set of greetings used by an application?
Choice 1
java.text.RuleBasedCollator
Choice 2
java.text.CollationKey
Choice 3
java.util.ResourceBundle
Choice 4
java.util.TimeZone
Choice 5
java.util.Locale
------------------------------------------------------------
|