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
System.out.println("Line " + i);
}
printOut(I-1);
}
What value should be passed to the method printOut, shown above, so that ten lines will be printed?
Choice 1
2
Choice 2
3
Choice 3
4
Choice 4
5
Choice 5
6
---------------------------------------------------------------------
Question Number 6
class A {
public static void main(String args[]) {
char initial = "c";
switch (initial) {
case "j":
System.out.print("John ");
break;
case "c":
System.out.print("Chuck ");
case "t":
System.out.print("Ty ");
break;
case "s":
System.out.print("Scott ");
default:
System.out.print("All");
}
}
}
What is the output from the code above?
Choice 1
John Chuck Ty Scott All
Choice 2
A compilation error will occur.
Choice 3
Chuck Ty
Choice 4
Ty
Choice 5
Chuck
---------------------------------------------------------------------
Question Number 7
How can you insure compatibility of persistent object formats between different versions of Java?
Choice 1
Override the default ObjectInputStream and ObjectOutputStream.
Choice 2
Implement your own writeObject() and readObject() methods.
Choice 3
Add "transient" variables.
Choice 4
Implement java.io.Serializable.
Choice 5
Make the whole class transient
---------------------------------------------------------------------
Question Number 8
What does it mean if a method is final synchronized?
Choice 1
Methods which are synchronized cannot be final.
Choice 2
This is the same as declaring the method private.
Choice 3
Only one synchronized method can be invoked at a time for the entire class.
Choice 4
The method cannot be overridden and is always threadsafe.
Choice 5
All final variables referenced in the method can be modified by only one thread at a time.
---------------------------------------------------------------------
Question Number 9
class HelloWorld extends java.awt.Canvas {
String str = "Hello World";
public void paint(java.awt.Graphics g) {
java.awt.FontMetrics fm = g.getFontMetrics();
g.setColor(java.awt.Color.black);
java.awt.Dimension d = getSize();
__?__
}
}
Which one of the following code segments can be inserted into the method above to paint "Hello World" centered within the canvas?
Choice 1
g.drawText( str, 0, 0);
Choice 2
g.drawString( str, d.width/2, d.height/2 );
Choice 3
g.drawString( str, d.width/2 - fm.stringWidth(str)/2, d.height/2 -
fm.getHeight()/2);
Choice 4
g.translate( d.width/2 - fm.stringWidth(str), d.height/2 - fm.getHeight());
g.drawString( str, 0, 0);
Choice 5
g.drawText( str, d.width, d.height, Font.CENTERED );
---------------------------------------------------------------------
Question Number 10
String url=new String("http://www.tek.com");
How can you retrieve the content of the above URL?
Choice 1
Socket content = new Socket(new URL(url)).collect();
Choice 2
String content = new URLConnection(url).collect();
Choice 3
Object content = new URL(url).getContent();
Choice 4
Object content = new URLConnection(url).getContent();
Choice 5
String content = new URLHttp(url).getString();
---------------------------------------------------------------------
Question Number 11
What is NOT a typical feature of visual JavaBeans?
Choice 1
Persistence, so a bean can be customized in an application builder, saved, and reloaded later.
Choice 2
Properties, both for customization and for programmatic use.
Choice 3
Customization, so that when using an application builder a developer can customize the appearance and behavior of a bean.
Choice 4
Distributed framework, so the visual component resides on the client, while the logic resides on the server.
Choice 5
Events, so that a simple communication metaphor can be used to connect beans.
---------------------------------------------------------------------
Question Number 12
Which one of the following describes the difference between StringBuffer and String?
Choice 1
StringBuffer is used only to buffer data from an input or output stream.
Choice 2
StringBuffer allows text to be changed after instantiation.
Choice 3
StringBuffer holds zero length Strings.
Choice 4
StringBuffer supports Unicode.
Choice 5
StringBuffer is an array of Strings.
---------------------------------------------------------------------
Question Number 13
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;
y *= -9.0;
try {
y = SquareRoot( y );
}
catch(ArithmeticException e) { y /= 3; }
finally { y += 10; }
return y;
}
Referring to the above, what value is returned when method func(9) is invoked?
Choice 1
-37
Choice 2
-27
Choice 3
-17
Choice 4
9
Choice 5
NaN
---------------------------------------------------------------------
Question Number 14
1: Date myDate = new Date();
2: DateFormat dateFormat = DateFormat.getDateInstance();
3: String myString = dateFormat.format(myDate);
4: System.out.println( "Today is " + myString );
How can you change line 2 above so that the date is displayed in the same format used in China?
Choice 1
java.util.Local locale = java.util.Locale.getLocale( java.util.Locale.CHINA );
DateFormat dateFormat = DateFormat.getDateInstance( locale );
Choice 2
java.util.Local locale = java.util.Locale.getLocale("China");
DateFormat dateFormat = DateFormat.getDateInstance( locale );
Choice 3
DateFormat dateFormat = DateFormat.getDateInstance();
dateFormat.setLocale( java.util.Locale.CHINA );
Choice 4
DateFormat dateFormat = DateFormat.getDateInstance(
DateFormat.SHORT, java.util.Locale.CHINA);
Choice 5
DateFormat.setLocale( java.util.Locale.CHINA );
DateFormat dateFormat = DateFormat.getDateInstance();
---------------------------------------------------------------------
Question Number 15
Which one of the following operators has a higher precedence than the modulus operator, % ?
Choice 1
-
Choice 2
*
Choice 3
+
Choice 4
/
Choice 5
. (dot)
---------------------------------------------------------------------
Question Number 16
double dd;
java.util.Random r = new Random(33);
dd = r.nextGaussian();
Referring to the above, after execution, double dd contains a value that is distributed approximately ________ with a standard deviation of ________ and mean of ________.
Choice 1
uniformly, 0, 33
Choice 2
normally, 1, 0
Choice 3
uniformly, 1, 33
Choice 4
normally, 1, 33
Choice 5
normally, 3, 3
---------------------------------------------------------------------
Question Number 17
How can you give other classes direct access to constant class attributes but avoid thread-unsafe situations?
Choice 1
Declare the attributes as public static final.
Choice 2
Implement the "java.lang.SingleThreaded" interface.
Choice 3
Declare the attributes to be synchronized.
Choice 4
This is not possible.
Choice 5
Declare the attributes as protected.
---------------------------------------------------------------------
Question Number 18
import java.io.*;
import java.net.*;
public class NetClient {
public static void main(String args[]) {
try {
Socket skt = new Socket("host",88);
In the above code, what type of connection is Socket object "skt"?
Choice 1
UDP
Choice 2
Connectionless
Choice 3
FTP
Choice 4
HTTP
Choice 5
Connection-oriented
---------------------------------------------------------------------
Question Number 19
float ff;
int gg = 99;
Referring to the above, what is the correct way to cast an integer to a float?
Choice 1
ff = (float) gg
Choice 2
ff (float) = gg
Choice 3
ff = (float: gg
Choice 4
ff = (float) %% gg
Choice 5
You cannot cast an integer to a float
---------------------------------------------------------------------
Question Number 20
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 prevent "hanging" using a MediaTracker object to ensure all frames are loaded before beginning
Choice 3
To draw the next frame to an off-screen image object before displaying to eliminate flicker
Choice 4
To put multiple frame in the same file and uses cropImage() to select the desired frame
Choice 5
To use a small image as wallpaper and a transparent image as the actual frame
---------------------------------------------------------------------
Question Number 21
Which one of the following is NOT a valid java.lang.String declaration?
Choice 1
String myString = new String("Hello");
Choice 2
char data[] = {'a','b','c'};
String str = new String(data);
Choice 3
String myString = new String(5);
Choice 4
String cde = "cde";
Choice 5
String myString = new String();
---------------------------------------------------------------------
Question Number 22
int count = 0;
while(count++ < os =" System.getProperty(" f =" new" count ="=" i="0;i<5;i=" here="" fileinputstream="" store="" objectinputstream="" additional="" produce="" type="" represented="" obj="in.readObject();" others="" 33="" declares="" called="" intarray="" two="" dimensional="" arrays="" allowed="" 34="" long="" compute="" primes="" larger="" than="" minprime="minPrime;" create="" start="" thread="" primethread="" p="new" runnable="" r="new" new="" 35="" mycanvas="" extends="" count="0;" void="" public="" graphics="" all="" declare="" there="" named="" name="all[i].equals(Class.instanceOf(all[i])))" as="" its="" overloaded="" methods="" cannot="" have="" input="" different="" return="" canvas="" so="" it="" 36="" objects="" can="" cast="" another="" following="" direct="" or="" subclass="" source="" both="" classes="" are="" subclasses="" same="" abstract="" target="" final="" 37="" happens="" if="" you="" load="" jdbc="" that="" fully="" compliant="" fail="" bytecode="" would="" function="" but="" may="" work="" actions="" not="" securitymanager="" throw="" securityexception="" when="" drivermanager="" object="" will="" refuse="" register="" 38="" sign="" javakey="" tool="" does="" one="" embeds="" flag="" attributes="" bottom="" creates="" an="" inner="" containing="" data="" array="" at="" top="" file="" places="" special="" signature="" files="" jar="" bundle="" 39="" g="2.0f;" double="" expected="" value="" h="3+f%g+2;" after="" 6="" 7="" 9="" 40="" connection="" con="DriverManager.getConnection" wombat="" login="" rs="stmt.executeQuery(" c="" from="" table1="" while="" integer="" x="rs.getInt(" float="" f="new" with="" retrieval="" of="" fields="" password="" must="" encrypted="" before="" being="" sent="" driver="" s="rs.getString(" url="" wrong="" resultset="" class="" returns="" primitive="" types="" for="" integers="" and="" sql="" is="" some="" multiple="" questions="" java="" ________________________________________="" which="" code="" segment="" execute="" stored="" procedure="" located="" in="new" a="" database="" callablestatement="" cs="con.prepareCall(" storeprocedurestatement="" spstmt="connection.createStoreProcedure(" preparestatement="" pstmt="connection.prepareStatement(" statement="" stmt="con.createStatement();" referring="" to="" the="" what="" datatype="" could="" be="" returned="" by="" method="" 1="" boolean="" 2="" string="" 4="" char="" choice="" 5="" byte="" question="" number="" 3="" int="" i="0;i
System.out.print("A ");
}
}
finally {
System.out.print("B ");
}
System.out.print("C ");
}
What is the output from the program above?
Choice 1
A B C A B C A B C
Choice 2
A A A B C A A A B C A A A B C
Choice 3
A A B C B B
Choice 4
A A B B C A C A
Choice 5
None. The program will enter into an infinite loop.