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="0;" x=" (check().equals(" total =" 0;" i =" new" j="1;j<=" ch1 =" (char)" ch2 =" '1';" ch2 =" '2';" ch2 =" '3';" ch2 =" '4';" b =" new" c =" (C)" n1 = "n1" n2 = "n2" n3 = "n3" n4 = "inner" n2 =" n1;" n3 =" null;" i =" values.length-1;">= 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 < j =" 0" ch1="'" j =" 0;" i =" 0" ch1 =" (char)" ch1 ="=" ch1 ="=" ch1 ="=" ch1 ="=" o =" new" out =" //..." i =" I;" i =" 0;" s1 =" new" s2 =" new" s3="s1.substring(1,5)" i="0;" j="1;j
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
No comments:
Post a Comment