Professional Documents
Culture Documents
Pro192
Pro192
Pro192
| By ge
tting a Set object from the Map and iterating through it.
What keyword is used to prevent an object from being serialized? | transient
An abstract class can contain methods with declared bodies. | True
Select the order of access modifiers from least restrictive to most restrictive
| public, protected, default, private
Which access modifier allows you to access method calls in libraries not create
d in Java? | native
Which of the following statements are true? (Select all that apply.) | D.
A final object cannot be reassigned a new address in memory.
The keyword extends refers to what type of relationship? | A. is a
Which of the following keywords is used to invoke a method in the parent clas
s? | B. super
public static void main(String [] a) { Funcs f = new Funcs(); System.out.pri
ntln("" + f.add(1, 2)); | C. The code does not compile.
public static void main(String [] a) { int [] b = [1,2,3,4,5,6,7,8,9,0]; Syst
em.out.println("a[2]=" + a[2]); | D. The code does not compile.
What is the value of x after the following operation is performed? x = 23 %
4; | D. 3
Given the following code, what keyword must be used at line 4 in order to stop
execution of the for loop? boolean b = true; for (;;) { if (b) { | C. break
What method call is used to tell a thread that it has the opportunity to run?
| B. notify()
Given the following code, which of the results that follow would you expect? p
ackage mail; interface Box { protected void open(); void close(); public void
empty(); | A. The code will not compile because of line 4.
Assertions are used to enforce all but which of the following? | C. Exceptio
ns
The developer can force garbage collection by calling System.gc(). | B. False
Select the valid primitive data types. (Select all that apply.) | boolean char f
loat
How many bits does a float contain? | 32
What is the value of x after the following line is executed? x = 32 * (31 -
10 * 3); | 32
A StringBuffer is slower than a StringBuilder, but a StringBuffer is threadsafe.
| A. True
Select the list of primitives ordered in smallest to largest bit size represent
ation. | D. char, int, float, long
Which class provides locale-sensitive text formatting for date and time informat
ion? | D. java.text.DateFormat
The following line of code is valid. int x = 9; byte b = x; | B. False
Which of the following code snippets compile? | A. Integer i = 7; B.
Integer i = new Integer(5); int j = i; C. byte b = 7;
What will be the output of the following code? public class StringTest { public
static void main(String [] a) { String s1 = "test string"; String s2 = "tes
t string"; if (s1 == s2) { System.out.println("same"); } else { System.out.pr
intln("different"); | D. same will be printed out to the console.
Java arrays always start at index 1. | False
Which of the following statements accurately describes how variables are passe
d to methods? | C. Arguments that are primitive type are passed by value.
How do you change the value that is encapsulated by a wrapper class after you
have instan- tiated it? | D. None of the above.
Suppose you are writing a class that provides custom deserialization. The class
implements java.io.Serializable (and not java.io.Externalizable). What method s
hould imple- ment the custom deserialization, and what is its access mode? | A.
private readObject
A signed data type has an equal number of non-zero positive and negative value
s available. | B. False
Choose the valid identifiers from those listed here. (Choose all that apply.) |
A. BigOlLongStringWithMeaninglessName B. $int C. bytes D. $1 E.
finalist
Which of the following signatures are valid for the main() method entry point of
an application? (Choose all that apply.) | B. public static void main(String
arg[]) D. public static void main(String[] args)
If all three top-level elements occur in a source file, they must appear in whi
ch order? | D. Package declaration, imports, class/interface/enum definitions.
Consider the following line of code: int[] x = new int[25]; After execution,
which statements are true? (Choose all that apply.) | A. x[24] is 0 E.
x.length is 25
Consider the following application: class Q6 { public static void main(String
args[]) { Holder h = new Holder(); h.held = 100; h.bump(h); System.out.println
(h.held); } } class Holder { public int held; public void bump(Holder theHolde
r) { theHolder.held++; }
Consider the following application: class Q7 { public static void main(String
args[]) { double d = 12.3; Decrementer dec = new Decrementer(); dec.decrement
(d); System.out.println(d); } } class Decrementer { public void decrement(doub
le decMe) { decMe = decMe - 1.0; | C. 12.3
How can you force garbage collection of an object? | A. Garbage collection cann
ot be forced.
What is the range of values that can be assigned to a variable of type short? |
D. -215 through 215 - 1
What is the range of values that can be assigned to a variable of type byte? | D
. -27 through 27 - 1
Suppose a source file contains a large number of import statements. How do the
imports affect the time required to compile the source file? | B. Compilat
ion takes slightly more time
Suppose a source file contains a large number of import statements and one cl
ass definition. How do the imports affect the time required to load the class?
| A. Class loading takes no additional time.
Which of the following are legal import statements? | A. import java.uti
l.Vector; C. import static java.util.Vector.*;
Which of the following may be statically imported? (Choose all that apply.) | B.
Static method names C. Static field names
What happens when you try to compile and run the following code? public class Q
15 { static String s; public static void main(String[] args) { System.out.pr
intln( >> + s + << ); | C. The code compiles, and prints out >>null<<
Which of the following are legal? (Choose all that apply.) | C. int c = 0xabcd
; D. int d = 0XABCD;
Which of the following are legal? (Choose all that apply.) | A. double d = 1.2
d; B. double d = 1.2D;
Which of the following are legal? | C. char c = \u1234 ;
Consider the following code: StringBuffer sbuf = new StringBuffer(); sbuf = nu
ll System.gc(); | C. After line 2 executes, the StringBuffer object is eligib
le for garbage collection.
Which of the following are true? (Choose all that apply.) | B. Primitives are p
assed by value. D. References are passed by value.
After execution of the following code fragment, what are the values of the var
iables x, a, and b? int x, a = 6, b = 7; x = a++ + b++; | C. x = 13,
a = 7, b = 8
Which of the following expressions are legal? (Choose all that apply.) | B.
int x = 6; if (!(x > 3)) {} C. int x = 6; x = ~x;
Which of the following expressions results in a positive value in x? | A.
int x = 1; x = x >>> 5;
Which of the following expressions are legal? (Choose all that apply.) | A.
String x = "Hello"; int y = 9; x += y; C. String x = "Hello"; int y =
9; x = x + y;
What is -8 % 5? | A. -3
What is 7 % -4? | B. 3
What results from running the following code? public class Xor { public static
void main(String args[]) { byte b = 10; // 00001010 binary byte c = 15; /
/ 00001111 binary b = (byte)(b ^ c); System.out.println("b contains " + b);
| B. The output: b contains 5
What results from attempting to compile and run the following code? public class
Conditional { public static void main(String args[]) { int x = 4; System.ou
t.println("value is " + ((x > 4) ? 99.99 : 9)); | C. The output: value is 9.
0
What does the following code do? Integer i = null; if (i != null & i.int
Value() == 5) System.out.println( Value is 5 ); | B. Throws an exception.
Is it possible to define a class called Thing so that the following method can
return true under certain circumstances? boolean weird(Thing s) { Integer x
= new Integer(5); return s.equals(x); | A. Yes
Suppose ob1 and ob2 are references to instances of java.lang.Object. If (ob1 =
= ob2) is false, can ob1.equals(ob2) ever be true? | B. No
When a byte is added to a char, what is the type of the result? | C. int
When a short is added to a float, what is the type of the result? | C. float
Which statement is true about the following method? int selfXor(int i) { retur
n i ^ i; | A. It always returns 0.
Which of the following operations might throw an ArithmeticException? | D.
/
What is the return type of the instanceof operator? | D. A boolean
Which of the following may appear on the left-hand side of an instance of oper
ator? | A. A reference
Which of the following may appear on the right-hand side of an instance of opera
tor? (Choose all that apply.) | B. A class C. An interface
What is -50 >> 1? | D. -25
Which of the following declarations are illegal? (Choose all that apply.) | A. d
efault String s; D. abstract double d; E. abstract final double hyperbolicCos
ine();
Which of the following statements is true? | B. A final class may not have any
abstract methods.
What is the minimal modification that will make this code compile correctly? fin
al class Aaa { int xxx; void yyy() { xxx = 1; } } class Bbb extends Aaa { fin
al Aaa finalref = new Aaa(); final void yyy() { System.out.println("In metho
d yyy()"); finalref.xxx = 12345; } } | A. On line 1, remove the final modifier.
4. Which of the following statements is true? | E. Transient variables are
not serialized
5. Which statement is true about this application? class StaticStuff { sta
tic int x = 10; static { x += 5; } public static void main(String args[]) {
System.out.println("x = " + x); } static {x /= 5; } } | E. The code compiles an
d execution produces the output x = 3.
6. Which statement is true about this code? class HasStatic { private stat
ic int x = 100; public static void main(String args[]) { HasStatic hs1 = new
HasStatic(); hs1.x++; HasStatic hs2 = new HasStatic(); hs2.x++; hs1 = new HasS
tatic(); hs1.x++; HasStatic.x++; System.out.println("x = " + x); } } | E. The pr
ogram compiles and the output is x = 104.
7. Given the following code, and making no other changes, which combination
of access modifiers (public, protected, or private) can legally be placed befor
e aMethod() on line 3 and be placed before aMethod() on line 8? class SuperDuper
{ void aMethod() { } } class Sub extends SuperDuper { void aMethod() { } }
| D. line 3: private; line 8: protected
8. Which modifier or modifiers should be used to denote a variable that sho
uld not be written out as part of its class s persistent state? (Choose the short
est possible answer.) | D. transient
11. Suppose class Supe, in package packagea, has a method called doSomething
(). Suppose class Subby, in package packageb, overrides doSomething(). What ac
cess modes may Subby s version of the method have? (Choose all that apply.) | A.
public B. protected
12. Which of the following statements are true? | F. None of the above.
13. Suppose interface Inty defines five methods. Suppose class Classy decla
res that it implements Inty but does not provide implementations for any of the
five interface methods. Which is/are true? | C. The class will compile if it is
declared abstract. D. The class may not be instantiated.
14. Which of the following may be declared final? (Choose all that apply.) |
A. Classes B. Data C. Methods
15. Which of the following may follow the static keyword? (Choose all that
apply.) | B. Data C. Methods D. Code blocks enclosed in curly brackets
16. Suppose class A has a method called doSomething(), with default access.
Suppose class B extends A and overrides doSomething(). Which access modes may
apply to B s version of doSomething()? (Choose all that apply.) | A. public C. pro
tected D. Default
17. True or false: If class Y extends class X, the two classes are in differ
ent packages, and class X has a protected method called abby(), then any insta
nce of Y may call the abby() method of any other instance of Y. | B. False
18. Which of the following statements are true? | D. A final class may not
be extended.
1. Which of the following statements is correct? (Choose one.) | D.
Both primitives and object references can be both converted and cast.
5. float f = 555.5f; 6. b = s; 7. i = c; | F. Line 6
4. In the following code, what are the possible types for variable result?
(Choose the most complete true answer.) 1. byte b = 11; 2. short s
= 13; 3. result = b * ++s; | E. int, long, float, double
6. Which of the following statements is true? (Choose one.) | D. Object r
eferences can be converted in both method calls and assignments, and the rule
s governing these conversions are identical.
is a set of java API for executing SQL statements. | JDBC
method is used to wait for a client to initiate communications. | accept()
drivers that are written partly in the Java programming language and partly in
native code. These drivers use a native client library specific to the data sour
ce to which they connect. Again, because of the native code, their portability i
s limited. | Type 2
drivers that are pure Java and implement the network protocol for a specific da
ta source. The client connects directly to the data source. | Type 4
drivers that use a pure Java client and communicate with a middleware server us
ing a database-independent protocol. The middleware server then communicates the
client's requests to the data source. | Type 3
drivers that implement the JDBC API as a mapping to another data access API, su
ch as ODBC. Drivers of this type are generally dependent on a native library, wh
ich limits their portability. | Type 1
26. System.out.println(a.doit(4, 5)); | Line 26 prints a to System.out.
Which two are true if a NullPointerException is thrown on line 3 of class C? (Ch
oose two.) | b. The code on line 29 will be executed. e. The exception wi
ll be propagated back to line 27.
dialog prevents user input to other windows in the application unitl the dialog
is closed. | Modal
A Java monitor must either extend Thread or implement Runnable. | False
A monitor called mon has 10 threads in its waiting pool; all these waiting threa
ds have the same priority. One of the threads is thr1. How can you notify thr1 s
o that it alone moves from the Waiting state to the Ready state? (Choose one.) |
You cannot specify which thread will get notified.
A signed data type has an equal number of non-zero positive and negative values
available. | False
A thread wants to make a second thread ineligible for execution. To do this, the
first thread can call the yield() method on the second thread. | False
An object is used to submit a query to a database | Statement
An object is uses to obtain a Connection to a Database | Driver Manager
Given a string constructed by calling s = new String("xyzzy"), which of the call
s modifies the string? (Choose one.) | None of the above
Given arrays a1 and a2, which call returns true if a1 and a2 have the same lengt
h, and a1[i].equals(a2[i]) for every legal index i? (Choose one.) | java.util.Ar
rays.equals(a1, a2);
A programmer wants to create an interface called B that has A as its parent. Whi
ch interface declaration is correct? | public interface B extends A { }
How can you force garbage collection of an object? (Choose one.) | Garbage colle
ction cannot be forced.
How do you prevent shared data from being corrupted in a multithreaded environme
nt? (Choose one.) | Access the variables only via synchronized methods.
How do you use the File class to list the contents of a directory? (Choose one.)
| String[] contents = myFile.list();
How many locks does an object have? (Choose one.) | 1
If all three top-level elements occur in a source file, they must appear in whic
h order? (Choose one.) | Package declaration, imports, class/interface/enum defi
nitions.
If class Y extends class X, the two classes are in different packages, and class
X has a protected method called abby(), then any instance of Y may call the abb
y() method of any other instance of Y. | False
If you need a Set implementation that provides value-ordered iteration, which cl
ass should you use? (Choose one.) | TreeSet
In order for objects in a List to be sorted, those objects must implement which
interface and method? (Choose one.) | Comparable interface and its compareTo me
thod.
Interface ... helps manage the connection between a Java program and a databas
e. | Connection
Is it possible to write code that can execute only if the current thread owns mu
ltiple locks? | Yes
DBC supports ... and ... models. | Two-tier and three-tier
MVC is short call of | Model-View-Controller
Select correct statement about RMI. (choose 1) | All the above
Select correct statement(s) about remote class.(choose one) | All the others cho
ices
Select correct statements about remote interface. (choose 1) | All the others ch
oices
Select INCORRECT statement about serialization. (choose 1) | When an Object Out
put Stream serializes an object that contains references to another object, ever
y referenced object is not serialized along with the original object.
Select INCORRECT statement about deserialize. (choose 1) | We use readObject() m
ethod of ObjectOutputStream class to deserialize.
Select incorrect statement about RMI server.(choose 1) | A client accesses a rem
ote object by specifying only the server name.
Select incorrect statement about ServerSocket class. (choose 1) | To make the ne
w object available for client connections, call its accept() method, which retur
ns an instance of ServerSocket
Select incorrect statement about Socket class. (choose 1) | The java.net.Socket
class contains code that knows how to find and communicate with a server through
UDP.
Select the correct statement about JDBC two-tier processing model. | A user's co
mmands are delivered to the database or other data source, and the results of th
ose statements are sent back to the user.
SQL keyword ... is followed by the selection criteria that specify the
rows to select in a query | WHERE
Statement objects return SQL query results as ... objects | ResultSetSupp
ose a source file contains a large number of import statements and one class def
inition. How do the imports affect the time required to load the class? (Choose
one.) | Class loading takes no additional time.
Suppose a source file contains a large number of import statements. How do the i
mports affect the time required to compile the source file? (Choose one.) | Comp
ilation takes slightly more time.
Suppose class A extends Object; Class B extends A; and class C extends B. Of the
se, only class C implements java.io.Externalizable. Which of the following must
be true in order to avoid an exception during deserialization of an instance of
C? (Choose one.) | C must have a no-args constructor.
Suppose class A has a method called doSomething(), with default access. Suppose
class B extends A and overrides doSomething(). Which access modes may not apply
to B s version of doSomething()? (Choose one) | private
Suppose prim is an int and wrapped is an Integer. Which of the following are leg
al Java statements? (Choose one.) | All the above
Suppose salaries is an array containing floats. Which of the following are valid
loop control statements for processing each element of salaries? (Choose one.)
| for (float f:salaries)
Suppose the declared type of x is a class, and the declared type of y is an inte
rface. When is the assignment x = y; legal? (Choose one.) | When the type of x i
s Object
Suppose the type of xarr is an array of XXX, and the type of yarr is an array of
YYY. When is the assignment xarr = yarr; legal? (Choose one.) | Sometimes
Suppose x and y are of type TrafficLightState, which is an enum. What is the bes
t way to test whether x and y refer to the same constant? (Choose one.) | if (x
== y)
Suppose you are writing a class that will provide custom deserialization. The cl
ass implements java.io.Serializable (not java.io.Externalizable). What access mo
de should the readObject() method have? (Choose one.) | private
Suppose you want to create a custom thread class by extending java.lang.Thread i
n order to provide some special functionality. Which of the following must you d
o? (Choose one.) | Override run().
Suppose you want to write a class that offers static methods to compute hyperbol
ic trigonometric functions. You decide to subclass java.lang.Math and provide th
e new functionality as a set of static methods. Which one statement is true abou
t this strategy? | The strategy fails because you cannot add static methods to a
subclass.
Swing components cannot be combined with AWT components. | true
The ... class is the primary class that has the driver information. | D
river Manager
The ... class is used to implement a pull-down menu that provides a num
ber of items to select from. | Menu
The element method alters the contents of a Queue. | False
The Swing component classes can be found in the package. | javax.swing
There are two classes in Java to enable communication using datagrams namely. |
DataPacket and DataSocket
URL referring to databases use the form: | protocol:subprotocol:datasoursename
What is -50 >> 2 | -13
What is 7 % -4? | 3
What is -8 % 5? | -3
What is the difference between the rules for method-call conversion and the rule
s for assignment conversion? (Choose one.) | There is no difference; the rules a
re the same.
What is the range of values that can be assigned to a variable of type byte? | -
2^7 through 2^7 - 1
What is the return type of the instanceof operator? | A boolean
What method of the java.io.File class can create a file on the hard drive? | cre
ateNewFile()
When a byte is added to a char, what is the type of the result? | int
When a negative byte is cast to a long, what are the possible values of the resu
lt? | Negative
When a negative long is cast to a byte, what are the possible values of the resu
lt? | All the above
When a short is added to a float, what is the type of the result? | float
When comparing java.io.BufferedWriter to java.io.FileWriter, which capability ex
ists as a method in only one of the two? | writing a line separator to the strea
m
When does an exception's stack trace get recorded in the exception object? | Whe
n the exception is constructed
When is it appropriate to pass a cause to an exception's constructor? | When the
exception is being thrown in response to catching of a different exception type
When is it appropriate to write code that constructs and throws an error? | neve
r
When is x & y an int? | sometimes
When the user attempts to close the frame window, ... event in generated. | w
indow closing
When the user selects a menu item, ... event is generated. | Action event
When you compile a program written in the Java programming language, the compile
r converts the human-readable source file into platform- independent code that a
Java Virtual Machine can understand. What is this platform-independent code cal
led? | bytecode
Whenever a method does not want to handle exceptions using the try block, the ..
. is used. | throws
Which class and static method can you use to convert an array to a List? | Array
s.asList
Which is four-step approach to help you organize your GUI thinking. | Identify n
eeded components. Isolate regions of behavior. Sketch the GUI. Choose layout man
agers.
Which is the four steps are used in working with JDBC? | Connect to the database
Create a statement and execute the query Look at the result set Close connectio
n
Which JDBC processing model that requires a JDBC driver that can communicate wi
th the particular data source being accessed? | two-tier
Which line of code tells a scanner called sc to use a single digit as a delimite
r? | sc.useDelimiter("\\d");
Which Man class properly represents the relationship "Man has the best friend wh
o is a Dog"? | class Man { private Dog bestFriend; }
Which methods return an enum constant s name? | name() toString()
Which modifier or modifiers should be used to denote a variable that should not
be written out as part of its class's persistent state? | transient
Which of the following are legal argument types for a switch statement? | byte i
nt char
Which of the following are legal loop definitions? | None of the above.
Which of the following are methods of the java.util.SortedSet interface? | All t
he above
Which of the following are true? | The JVM runs until there are no non-daemon t
hreads.
Which of the following are true? | An enum may contain public method definition
s. An enum may contain private data.
Which of the following are true? | Primitives are passed by value. References a
re passed by value.
Which of the following are true? | An anonymous inner class may implement at mo
st one interface. An anonymous inner class may extend a parent class other than
Object.
Which of the following are valid arguments to the DataInputStream constructor? |
FileInputStream
Which of the following are valid mode strings for the RandomAccessFile construct
or? | All the above
Which of the following calls may be made from a non-static synchronized method?
| All the above
Which of the following classes implement java.util.List? | java.util.ArrayList
java.util.Stack
Which of the following classes implements a FIFO Queue? | LinkedList
Which of the following expressions results in a positive value in x? | int x = 1;
x = x >>> 5;
Which of the following interfaces does not allow duplicate objects? | set
Which of the following is not appropriate situations for assertions? | Precondit
ions of a public method
Which of the following is NOTa valid comment: | /* comment
Which of the following is the most appropriate way to handle invalid arguments i
n a public method? | Throw java.lang.IllegalArgumentException.
Which of the following may appear on the left-hand side of an instance of operat
or? | A reference
Which of the following may appear on the right-hand side of an instance of opera
tor? (Choose two.) | Class interface
Which of the following may be declared final? (Choose two.) | Classes Methods
Which of the following may be statically imported? (Choose two.) | Static method
names Static field names
Which of the following may legally appear as the new type (between the parenthes
es) in a cast operation? (Choose one.) | All of the others
Which of the following may not be synchronized? (Choose one.) | Classes
Which of the following methods in the Thread class are deprecated? (Choose one.)
| suspend() and resume()
Which of the following operations might throw an ArithmeticException? (Choose on
e.) | None of these
Which of the following operations might throw an ArithmeticException? (Choose on
e.) | /
Which of the following operators can perform promotion on their operands? (Choos
e three.) | + - ~
Which of the following restrictions apply to anonymous inner classes? (Choose on
e.) | They must be defined inside a code block.
Which of the following should always be caught? (Choose one.) | Checked exceptio
ns
Which of the following signatures are valid for the main() method entry point of
an application? (Choose two.) | public static void main(String[] args) public s
tatic void main(String arg[])
Which of the following statements about the wait() and notify() methods is true?
(Choose one.) | The thread that calls wait() goes into the monitor s pool of wait
ing threads.
Which of the following statements about threads is true? (Choose one.) | Threads
inherit their priority from their parent thread.
Which of the following statements are true? (Choose one.) | A final class may no
t be extended.
Which of the following statements are true? (Choose one.) | Given that Inner is
a nonstatic class declared inside a public class Outer and that appropriate cons
tructor forms are defined, an instance of Inner can be constructed like this: ne
w Outer().new Inner()
Which of the following statements is correct? (Choose one.) | Both primitives an
d object references can be both converted and cast.
Which of the following statements is true? (Choose one.) | Transient variables a
re not serialized.
Which of the following statements is true? (Choose one.) | Object references can
be converted in both method calls and assignments, and the rules governing thes
e conversions are identical.
Which of the statements below are true? (Choose one.) | Unicode characters are a
ll 16 bits.
is a set of java API for executing SQL statements | JDBC
method is used to wait for a client to initiate communications | accept()
drivers that are written partly in the Java programming language and partly in n
ative code. These drivers use a native client library specific to the data sourc
e to which they connect | Type 2
drivers that are pure Java and implement the network protocol for a specific dat
a source. The client connects directly to the data source | Type 4
drivers that use a pure Java client and communicate with a middleware server usi
ng a database-independent protocol. The middleware server then communicates the
client's requests to the data source | Type 3
drivers that implement the JDBC API as a mapping to another data access API, suc
h as ODBC. Drivers of this type are generally dependent on a native library, whi
ch limits their portability | Type 1
System.out.println(a.doit(4, 5)) | Line 26 prints a to System.out
Which two are true if a NullPointerException is thrown on line 3 of class C | co
de on line 29, The exception
What lines are output if the constructor at line 3 throws a MalformedURLExceptio
n | Bad URL, Doing finally, Carrying
What lines are output if the methods at lines 3 and 5 complete successfully with
out throwing any exceptions | Success, Doing, Carrying
If lines 24, 25 and 26 were removed, the code would compile and the output would
be 1 | 3.The code, would be 1, 2
An exception is thrown at runtime | An exception
first second first third snootchy 420 | third second first snootchy 420
dialog prevents user input to other windows in the application unitl the dialog
is closed | Modal
You would like to write code to read back the data from this file. Which solutio
ns will work | 2.FileInputStream, RandomAccessFile
A Java monitor must either extend Thread or implement Runnable | F
A monitor called mon has 10 threads in its waiting pool; all these waiting threa
ds have the same priority. One of the threads is thr1 | You cannot specify
A programmer needs to create a logging method that can accept an arbitrary numbe
r of arguments. For example, it may be called in these ways | public void logIt(
String... msgs)
A signed data type has an equal number of non-zero positive and negative values
available | F
A thread wants to make a second thread ineligible for execution. To do this, the
first thread can call the yield() method on the second thread | F
catch (InterruptedException e) | running some time
object is used to submit a query to a database | Statement
object is uses to obtain a Connection to a Database | DriverManager
After execution of the following code fragment, what are the values of the varia
bles x, a, and b | x13, a7, b8
Yen and Euro both return correct Country value | 2.Euro returns, error at line
25
BigOlLongStringWithMeaninglessName | tick all
Compilation of class A will fail. Compilation of class B will succeed | B fail,
A succeed
Line 46 will compile if enclosed in a try block, where TestException is caught |
2.if the enclosing, is caught
Holder h = new Holder() | 101
Decrementer dec = new Decrementer() | 12.3
Test t = (new Base()).new Test(1) | 2.new Test(1), new Test(1, 2)
Base(int j, int k, int l) | 2.Base(), Base(int j, int k)
Line 12 will not compile, because no version of crunch() takes a char argument |
output: int version
output results when the main method of the class Sub is run | Value 5 This value
6
Float floater = new Float(3.14f) | Line 6
The application must be run with the -enableassertions flag or another assertion
enabling flag | dai nhat, one or more
After line 3 executes, the StringBuffer object is eligible for garbage collectio
n | line 2 executes..collection
The code will compile but will throw an exception at line 7, because runtime con
version from an interface to a class is not permitted | type SwampThing
The code will compile and run, but the cast in line 6 is not required and can be
eliminated | The code will compile and run
for (int i = 0; i < 2; i++) | 4.i0,j12 - i1,j02
outer: for (int i = 0; i < 2; i++) | i = 1 j = 0
The code will compile but will throw an exception at line 7, because runtime con
version from an interface to a class is not permitted | Line 7 will not compile
int[] x = new int[25] | 2.x[24]=0, x.length is 25
public float aMethod(float a, float b) throws Exception | int a,b float p,q
public float aMethod(float a, float b, int c) throws Exception | 3.int a,b. floa
t a,b-int c. private
Given a string constructed by calling s = new String("xyzzy"), which of the call
s modifies the string | None of the above
Given arrays a1 and a2, which call returns true if a1 and a2 have the same lengt
h, and a1[i].equals(a2[i]) for every legal index i | Arrays.equals(a1, a2)
Assuming the class does not perform custom serialization, which fields are writt
en when an instance of Xyz is serialized | 3.Public, Private, Volatile
can legally be placed before aMethod() on line 3 and be placed before aMethod()
on line 8 | 3: private; 8: protected
NUTMEG, CINNAMON, CORIANDER, ROSEMARY | 3.Spice sp, Spice, String
List<String> names = new ArrayList<String>() | 2.Iterator, for
Compilation fails because of an error in line 15 | error in line 19
1 2 3 | 2 3
public interface B inheritsFrom A | B extends A
protected double getSalesAmount() { return 1230.45; } | 2.public, protected
Line 16 creates a directory named d and a file f within it in the file system |
3.An
exception, Line 13, line 14
Nav.Direction d = Nav.Direction.NORTH | Nav.Direction.NORTH
new class Foo { public int bar() { return 1; } } | new Foo()
IllegalArgumentException | StackOverflowError
Circle c = new Circle(); c.Shape.setAnchor(10,10); c.Shape.draw() | Shape s = ne
w Circle...s.draw()
Compilation fails because of an error in line 12 | 1 2 3
NullPointerException | Compilation fails
A NumberFormatException is thrown by the parse method at runtime | Compilation f
ails
An exception is thrown at runtime | Compilation fails
passed An AssertionException is thrown without the word stuff added to the stack t
race | An AssertionError...with the
collie | collie harrier
doStuff x = 6 main x = 6 | doStuff x =5 main x =5
The setCardlnformation method breaks encapsulation | The ownerName
The value of all four objects prints in natural order | Compilation fails...line
29
The code on line 33 executes successfully | 3.33 throws, 35 throws, 33 executes
What is the result if a NullPointerException occurs on line 34 | ac
Compilation will fail because of an error in line 55 | Line 57...value 3
java -ea test file1 file2 | 2.java -ea test, dai nhat
String s = 123456789 ; s = (s- 123 ).replace(1,3, 24 ) - 89 | 2.delete(4,6),
delete(2,5)
rt( 1, 24 )
The Point class cannot be instatiated at line 15 | Line.Point p = new Line.Point
()
for( int i=0; i< x.length; i++ ) System.out.println(x[i]) | 2.for(int z : x),
dai nhat
int MY_VALUE = 10 | 3.final, static, public
Compilation fails because of an error in line: public void process() throws Runt
imeException | A Exception
How can you ensure that multithreaded code does not deadlock | There is no singl
e
How can you force garbage collection of an object | Garbage collection
How do you prevent shared data from being corrupted in a multithreaded environme
nt | Access the variables
How do you use the File class to list the contents of a directory | String[] con
tents
The number of bytes depends on the underlying system | 8
How many locks does an object have | One
If all three top-level elements occur in a source file, they must appear in whic
h order | Package declaration, imports
the two classes are in different packages, and class X has a protected method ca
lled abby(), then any instance of Y may call the abby() method of any | F
TestThread3 ttt = new TestThread3 | Y
If you need a Set implementation that provides value-ordered iteration, which cl
ass should you use | TreeSet
In order for objects in a List to be sorted, those objects must implement which
interface and method | Comparable...compareTo
after execution of line 1, sbuf references an instance of the StringBuffer class
. After execution of line 2, sbuf still references the same instance | T
what are the possible types for variable result | int, long, float, double
helps manage the connection between a Java program and a database | Connection
Is it possible to define a class called Thing so that the following method can r
eturn true under certain circumstances | Y
Is it possible to write code that can execute only if the current thread owns mu
ltiple locks | Y
JDBC supports ______ and ______ models | Two-tier and three-tier
MVC is short call of | Model-View-Controller
No output because of compile error at line: System.out.println("b="+b) | b = b *
b1
Object ob2= new Object() | Have a nice day
Object ob2= ob1 | ob1 equals ob2, ob1==ob2
String s2 = "xyz" | Line 4, Line 6
String s2 = new String("xyz") | Line 6
String s2 = new String(s1) | Line 6
Select correct statement about RMI | All the above
Select correct statement(s) about remote class | All the others choices
Select correct statements about remote interface | All the others choices
Select INCORRECT statement about serialization | When an Object Output
Select INCORRECT statement about deserialize | We use readObject
Select incorrect statement about RMI server | A client accesses
Select incorrect statement about ServerSocket class | To make the new object
Select incorrect statement about Socket class | server through UDP
Select the correct statement about JDBC two-tier processing model | A user's com
mands
SQL keyword ___ is followed by the selection criteria that specify the rows to s
elect in a query | WHERE
Statement objects return SQL query results as | ResultSet
When a JDBC connection is created, it is in auto-commit mode | Both 1 and 2 are
true
Suppose a method called finallyTest() consists of a try block, followed by a cat
ch block, followed by a finally block | If the JVM doesn't crash
Suppose a source file contains a large number of import statements and one class
definition. How do the imports affect the time required to load the class | no
additional time
Suppose a source file contains a large number of import statements. How do the i
mports affect the time required to compile the source file | slightly more time
Suppose class A extends Object; Class B extends A; and class C extends B. Of the
se, only class C implements java.io.Externalizable | C must have a
Suppose class A extends Object; class B extends A; and class C extends B. Of the
se, only class C implements java.io.Serializable | B must have a
Suppose class A has a method called doSomething(), with default access. Suppose
class B extends A and overrides doSomething() | private
Suppose class Supe, in package packagea, has a method called doSomething(). Supp
ose class Subby, in package packageb, overrides doSomething() | 2.public, protec
ted
void doSomething(int a, float b) | public...(int a, float b)
Suppose interface Inty defines five methods. Suppose class Classy declares that
it implements Inty but does not provide implementations for any of the five inte
rface methods | 2.declared abstract, may not be
Suppose prim is an int and wrapped is an Integer. Which of the following are leg
al Java statements | All the above
Suppose salaries is an array containing floats. Which of the following are valid
loop control statements for processing each element of salaries | for (float f:
salaries)
Suppose the declared type of x is a class, and the declared type of y is an inte
rface. When is the assignment x = y; legal | When the...x is Object
Suppose the type of xarr is an array of XXX, and the type of yarr is an array of
YYY. When is the assignment xarr = yarr; legal | Sometimes
Suppose x and y are of type TrafficLightState, which is an enum. What is the bes
t way to test whether x and y refer to the same constant | if (x == y)
Suppose you are writing a class that will provide custom deserialization. What a
ccess mode should the readObject() method have | private
Suppose you are writing a class that will provide custom serialization. What acc
ess mode should the writeObject() method have | private
Suppose you want to create a custom thread class by extending java.lang.Thread i
n order to provide some special functionality | Override run()
Suppose you want to write a class that offers static methods to compute hyperbol
ic trigonometric functions. You decide to subclass java.lang.Math and provide th
e new functionality as a set of static methods | subclass java.lang.Math
Swing components cannot be combined with AWT components | T
class is the primary class that has the driver information | DriverManager
class is used to implement a pull-down menu that provides a number of items to s
elect from | Menu
The element method alters the contents of a Queue | F
The Swing component classes can be found in the | javax.swing
There are two classes in Java to enable communication using datagrams namely | D
ataPacket and DataSocket
Compilation of Parrot.java fails at line 7 because method getRefCount() is stati
c in the superclass, and static methods may not be overridden to be nonstatic |
dai nhat: nonstatic
Compilation of Nightingale will succeed, but an exception will be thrown at line
10, because method fly() is protected in the superclass | The program...After:
2
void doSomething() throws IOException, EOFException | ngan-dai nhat, throws EOFE
xception
URL referring to databases use the form | protocol:subprotocol:datasoursename
What are the legal types for whatsMyType | There are no possible legal types
What does the following code do | Throws an exception
There is no output because the code throws an exception at line 1 | output is i
= 20
1000 | -1
What happens when you try to compile and run the following application | thrown
at line 9
The code compiles, and prints out >>null<< | out >>null<<
An exception is thrown at line 6 | thrown at line 7
What is -50 >> 2 | -13
What is 7 % -4 | 3
What is -8 % 5 | -3
What is the difference between the rules for method-call conversion and the rule
s for assignment conversion | There is no difference
The code will compile as is. No modification is needed | On line 1, remove
What is the range of values that can be assigned to a variable of type byte | ?2
mu7 through 2mu7 ? 1
What is the range of values that can be assigned to a variable of type short | ?
2mu15 through
The code compiles and executes; afterward, the current working directory contain
s a file called datafile | The code fails to compile
What is the return type of the instanceof operator | A boolean
What method of the java.io.File class can create a file on the hard drive | crea
teNewFile()
The output: value is 99.99 | value is 9.0
The output: b contains 250 | b contains 5
What would be the output from this code fragment | message four
When a byte is added to a char, what is the type of the result | int
When a negative byte is cast to a long, what are the possible values of the resu
lt | Negative
When a negative long is cast to a byte, what are the possible values of the resu
lt | All the above
When a short is added to a float, what is the type of the result | float
When comparing java.io.BufferedWriter to java.io.FileWriter, which capability ex
ists as a method in only one of the two | writing a line
When does an exception's stack trace get recorded in the exception object | is c
onstructed
When is it appropriate to pass a cause to an exception's constructor | in respon
se to catching
When is it appropriate to write code that constructs and throws an error | Never
When is x & y an int | Sometimes
When the user attempts to close the frame window, _______ event in generated | w
indow closing
When the user selects a menu item, _______ event is generated | Action event
Java programming language, the compiler converts the human-readable source file
into platform-independent code that a Java Virtual Machine can understand | byte
code
Whenever a method does not want to handle exceptions using the try block, the |
throws
Which are the correct statements used for getting connection object to connect t
o SQL Server database | String url =jdbc:odbc
Which class and static method can you use to convert an array to a List | Arrays
.asList
Which is four-step approach to help you organize your GUI thinking | Identify, I
solate, Sketch
Which is the four steps are used in working with JDBC | Connect, Create, Look
Which JDBC processing model that requires a JDBC driver that can communicate wi
th the particular data source being accessed | two-tier
Which line of code tells a scanner called sc to use a single digit as a delimite
r | sc.useDelimiter("\\d")
Man has the best friend who is a Dog | private Dog bestFriend
Which methods return an enum constant s name | 2.name(), toString()
Which modifier or modifiers should be used to denote a variable that should not
be written out as part of its class's persistent state | transient
Which of the following are legal argument types for a switch statement | 3.byte,
int, char
Which of the following are legal enums | 3.ngan-dai nhat, lion int weight
Which of the following are legal import statements | 2.import...Vector, Vector.*
Which of the following are legal loop constructions | for (int k=0, j+k != 10; j
++,k++)
Which of the following are legal loop definitions | None of the above
double d = 1.2d5 | 2.double d = 1.2d, 1.2D
int d = 0XABCD | 2.int c = 0xabcd, dai nhat
char c = 0x1234 | 2.0x.., '\u1234'
Vector <String> theVec = new Vector<String>() | 2.List...<String>(), dai nhat
Which of the following are methods of the java.util.SortedMap interface | headMa
p, tailMap, subMap
Which of the following are methods of the java.util.SortedSet interface | All th
e above
System.out has a println() method | All the above
The JVM runs until there is only one non-daemon thread | are no non-daemon
When an application begins running, there is one non-daemon thread, whose job is
to execute main() | 3.nhat, thread, non-daemon thread
When you declare a block of code inside a method to be synchronized, you can spe
cify the object on whose lock the block should synchronize | 2.the method always
, nhat
An enum definition should declare that it extends java.lang.Enum | 2.contain pub
lic, private
Primitives are passed by reference | 2.by value
An anonymous inner class that implements several interfaces may extend a parent
class other than Object | implement at most, class may extend
Which of the following are valid arguments to the DataInputStream constructor |
FileInputStream
Which of the following are valid mode strings for the RandomAccessFile construct
or | All the above
Which of the following calls may be made from a non-static synchronized method |
All the above
Which of the following classes implement java.util.List | 2.ArrayList, Stack
Which of the following classes implements a FIFO Queue | LinkedList
Which of the following declarations are illegal | 3.ngan-dai nhat, double d
int x = 6; if (!(x > 3)) | 2.dai nhat, x = ~x
String x = "Hello"; int y = 9; if (x == y) | 2.ngan nhat, x=x+y
Which of the following expressions results in a positive value in x | int x = 1;
x = x >>> 5
Which of the following interfaces does not allow duplicate objects | Set
Which of the following is not appropriate situations for assertions | Preconditi
ons of a public method
Which of the following is NOTa valid comment | /* comment
Which of the following is the most appropriate way to handle invalid arguments i
n a public method | IllegalArgumentException
Readers have methods that can read and return floats and doubles | None of the a
bove
An enum definition may contain the main() method of an application | All the abo
ve
Which of the following may appear on the left-hand side of an instanceof operato
r | A reference
Which of the following may appear on the right-hand side of an instanceof operat
or | 2.A class, An interface
Which of the following may be declared final | 2.Classes, Methods
Which of the following may be statically imported | 2.Static method, Static fiel
d
Which of the following may follow the static keyword | 3.Data, Methods, Code blo
cks
Which of the following may legally appear as the new type (between the parenthes
es) in a cast operation | All of
Which of the following may not be synchronized | Classes
Which of the following may override a method whose signature is void xyz(float f
) | 2.void, public void xyz(float f)
Which of the following methods in the Thread class are deprecated | suspend() an
d resume()
Which of the following operations might throw an ArithmeticException | None of
Which of the following operators can perform promotion on their operands | 3.con
g, tru, xap xi
Which of the following restrictions apply to anonymous inner classes | must be d
efined
Which of the following should always be caught | Checked exceptions
Which of the following signatures are valid for the main() method entry point of
an application | 2.static void...(String arg[])
Which of the following statements about the wait() and notify() methods is true
| calls wait() goes into
Which of the following statements about threads is true | Threads inherit their
A final class may not contain non-final data fields | may not be extended
An abstract class must declare that it implements an interface | None
An abstract class may not have any final methods | Only statement 2
Only object references are converted automatically; to change the type of a prim
itive, you have to do a cast | Both primitives
Transient methods may not be overridden | variables are not
Object references can be converted in both method calls and assignments, but the
rules governing these conversions are very different | conversions are identica
l
Bytecode characters are all 16 bits | Unicode characters
To change the current working directory, call the changeWorkingDirectory() metho
d of the File class | None
When you construct an instance of File, if you do not use the file-naming semant
ics of the local machine, the constructor will throw an IOException | None
When the application is run, thread hp1 will execute to completion, thread hp2 w
ill execute to completion, then thread hp3 will execute to completion | None of
Compilation succeeds, although the import on line 1 is not necessary. During exe
cution, an exception is thrown at line 3 | fails at line 2
Compilation fails at line 1 because the String constructor must be called explic
itly | succeeds. No exception
Line 4 executes and line 6 does not | Line 6 executes
There will be a compiler error, because class Greebo does not correctly implemen
t the Runnable interface | Runnable interface
The acceptable types for the variable j, as the argument to the switch() constru
ct, could be any of byte, short, int, or long | value is three
The returned value varies depending on the argument | returns 0
Lines 5 and 12 will not compile because the method names and return types are mi
ssing | output x = 3
Line 13 will not compile because it is a static reference to a private variable
| output is x = 104
Which statements about JDBC are NOT true | 2.database system, DBMS
Which two code fragments correctly create and initialize a static array of int
elements | 2.a = { 100,200 }, static
Which two of the following interfaces are at the top of the hierarchies in the J
ava Collections Framework | 2.Map, Collection
A new directory called dirname and a new file called filename are created, both
in the current working directory | No directory
protected class Cat extends Owner | public class Cat extends Pet
Date vaccinationDue | 2.boolean, String
What is -15 % -10 | -5
command line on a Windows system | 2.must contain the statement, the file
The string created on line 2 does not become eligible for garbage collection in
this code | After line 3
When the application runs, what are the values of n and w.x after the call to bu
mp() in the main | n is 10, w.x is 11
The addAll() method of that interface takes a single argument, which is a ref
erence to a collection whose elements are compatible with E. What is the declar
ation of the addAll() method | addAll(Collection<? extends E> c)
If you want a vector in which you know you will only store strings, what are the
advantages of using fancyVec rather than plainVec | Attempting to...compiler er
ror
When should objects stored in a Set implement the java.util.Comparable interfac
e | Set is a TreeSet
What relationship does the extends keyword represent | is a
class bbb.Bbb, which extends aaa.AAA, wants to override callMe(). Which access m
odes for callMe() in aaa.AAA will allow this | 2.public, protected
Lemon lem = new Lemon(); Citrus cit = new Citrus() | 3.cit = lem, cit=(Citrus),
lem=(lemon)
it also has a method called chopWoodAndCarryWater(), which just calls the other
two methods | inappropriate cohesion, inappropriate coupling
sharedOb.wait() | 2.aThread.interrupt, sharedOb.notifyAll
line prints double d in a left-justified field that is 20 characters wide, with
15 characters to the right of the decimal point | System.out.format("%-20.15f",
d)
What code at line 3 produces the following output | String delim = \\d+
How do you generate a string representing the value of a float f in a format a
ppropriate for a locale loc | NumberFormat.getInstance(loc)
you want to use a DateFormat to format an instance of Date. What factors influ
ence the string returned by DateFormat s format() method | 2.LONG, or FULL, The lo
cale
you want to create a class that compiles and can be serialized and deserialized
without causing an exception to be thrown. Which statements are true regarding
the class | 2.dai nhat, ngan nhat
you are writing a class that will provide custom deserialization. The class impl
ements java.io.Serializable (not java.io.Externalizable) | private
What interfaces can be implemented in order to create a class that can be serial
ized | 2.dai nhat, ngan nhat
The file contains lines of 8-bit text, and the 8-bit encoding represents the lo
cal character set, as represented by the cur- rent default locale. The lines are
separated by newline characters | FileReader instance
shorty is a short and wrapped is a Short | all
How is IllegalArgumentException used | 2.certain methods, public methods
While testing some code that you are developing, you notice that an ArrayIndexO
utOf- BoundsException is thrown. What is the appropriate reaction | None
Which lines check that x is equal to four? Assume assertions are enabled at com
pile time and runtime | 2.assert x == 4
int[] ages = { 9, 41, 49 }; int sum = 0 | 2.i<ages.length, for (int i:ages)
Which of the following types are legal arguments of a switch statement | enums,
bytes
class A extends java.util.Vector { private A(int x) | does not create a defau
lt
void callMe(String names) | method, names is an array
Given a class with a public variable theTint of type Color, which of the followi
ng methods are consistent with the JavaBeans naming standards | public Color ge
tTheTint()
are valid arguments to the DataInputStream constructor | FileInputStream
are valid mode strings for the RandomAccessFile constructor | r, rw, rws, rwd
method of the java.io.File class can create a file on the hard drive | createNe
wFile()
class A extends Object; Class B extends A; and class C extends B. Of these, only
class C implements java.io.Externalizable | C must have
class A extends Object; class B extends A; and class C extends B. Of these, only
class C implements java.io.Serializable | B must have
you are writing a class that will provide custom deserialization. The class impl
ements java.io.Serializable (not java.io.Externalizable) | private
you are writing a class that will provide custom serialization. The class implem
ents java.io.Serializable (not java.io.Externalizable) | private
How do you use the File class to list the contents of a directory | String[] c
ontents = myFile.list();
call returns true if a1 and a2 have the same length, and a1[i].equals(a2[i]) fo
r every legal index i | java.util.Arrays.equals(a1, a2)
line of code tells a scanner called sc to use a single digit as a delimiter | sc
.useDelimiter( \\d )
you want to write a class that offers static methods to compute hyperbolic trigo
nometric functions. You decide to subclass java.lang.Math and provide the new f
unctionality as a set of static methods | java.lang.Math
Given a string constructed by calling s = new String( xyzzy ), which of the calls
mo
difies the string | none
Suppose you want to create a custom thread class by extending java.lang.Thread
in order to provide some special functionality. Which of the following must you
do | Override run()
you prevent shared data from being corrupted in a multithreaded environment | Ac
cess the variables
Is it possible to write code that can execute only if the current thread owns
multiple locks | yes
Which of the following may not be synchronized | Classes
statements about the wait() and notify() methods is true | pool of waiting th
reads
methods in the Thread class are deprecated | suspend() and resume()
A Java monitor must either extend Thread or implement Runnable | F
One of the threads is thr1. How can you notify thr1 so that it alone moves from
the Waiting state to the Ready state | You cannot specify
A thread wants to make a second thread ineligible for execution. To do this,
the first thread can call the yield() method on the second thread | F
Which methods return an enum constant s name | name(), toString()
restrictions apply to anonymous inner classes | inside a code block
A pet has an owner, a registration date, and a vaccination-due date. A cat is a
pet that has a flag indicating whether it has been neutered, and a textual d
escription of its markings | boolean, string
Which of the following are valid declarations? Assume java.util | 1Vector 2Set 3
Map string,string
You can determine all the keys in a Map in which of the following ways | Set ob
ject from the Map
What keyword is used to prevent an object from being serialized | transient
abstract class can contain methods with declared bodies. | E. public, protecte
d, default, private
access modifier allows you to access method calls in libraries not created in J
ava | native
Which of the following statements are true? (Select all that apply.) | object c
annot reassigned
The keyword extends refers to what type of relationship | is a
keywords is used to invoke a method in the parent class | super
What is the value of x after the following operation is performed | 3
method call is used to tell a thread that it has the opportunity | notify()
Assertions are used to enforce all but which | Exceptions
force garbage collection by calling System.gc(). | B. False
Select the valid primitive data type | 1.boolean 2.char 3.float
How many bits does a float contain | 32
What is the value of x after the following line is executed | 32
StringBuffer is slower than a StringBuilder, but a StringBuffer | True
list of primitives ordered in smallest to largest bit size representation | D.
char, int, float, long
Which class provides locale-sensitive text formatting for date and time informat
ion | java.text.DateFormat
int x = 9; byte b = x | False
Which of the following code snippets compile | 1.Integer 2.Integer 3.byte
Java arrays always start at index 1 | False
accurately describes how variables are passed to methods | that are primitive t
ype are passed by value
change the value that is encapsulated by a wrapper class after you have instan
| None of the above.
The class implements java.io.Serializable (and not java.io.Externalizable) | pri
vate readObject
A signed data type has an equal number of non-zero positive and negative value
s | False
signatures are valid for the main() method entry point of an application | publi
c static void main(String[] args)
three top-level elements occur in a source file, they must appear | Package decl
aration, imports, class/interface/enum definitions
int[] x = new int[25] | x[24] is 0 and x.length is 25
How can you force garbage collection of an object | Garbage collection cannot
be forced.
range of values that can be assigned to a variable of type short | -215 through
215 - 1
range of values that can be assigned to a variable of type byte | -27 through 2
7 - 1
How do the imports affect the time required to compile the source file | Compi
lation takes slightly more time
How do the imports affect the time required to load the class? | Class loading
takes no additional time
legal import statements | 1.import java.util.Vector 2.import static java.ut
il.Vector
may be statically imported | 1.Static method names 2.Static field names
int c = 0xabcd and int d = 0XABCD | 2 dap an
double d = 1.2d and double d = 1.2D | 2 dap an
char c = \u1234 | 1 dap an
passed by value and passed by value | 2 dap an
int x = 6; if (!(x > 3)) and int x = 6; x = ~x | 2 dap an
int x = 1; x = x >>> 5 | 1 dap an
int y = 9; x += y; and int y = 9; x = x + y; | 2 dap an
What is -8 % 5 | -3
What is 7 % -4? | 3
ob1 == ob2 | No
When a byte is added to a char | int
When a short is added to a float | float
ArithmeticException | 1.None of these 2./
What is the return type of the instanceof operator | boolean
may appear on the left-hand side of an instanceof operator | reference
may appear on the right-hand side of an instanceof operator | class and interfa
ce
What is -50 >> 1 | -25
default String s ,, abstract double d ,, double hyperbolic | 3 dap an
A final class may not have any abstract methods | true
denote a variable that should not be written out as part of its class s persistent
state | transient
Both primitives and object references can be both converted and cast | dap an
and the rules governing these conversions are identical | dap an
may legally appear as the new type (between the parentheses) in a cast operati
on | All of the above
type of x is a class, and the declared type of y is an interface. When is the as
signment x = y | When the type of x is Object
xarr is an array of XXX, and the type of yarr is an array of YYY | Sometimes
When is x & y an int | Sometimes
negative long is cast to a byte | All of the above
negative byte is cast to a long | Negative
operators can perform promotion on their operands | + - ~(nga)
difference between the rules for method-call conversion and the rules for assign
ment conversion | There is no difference
Which of the following are appropriate situations for assertions | DAP AN SAI :
Preconditions of a public method
appropriate way to handle invalid arguments in a public method | IllegalArgumen
tException
Suppose salaries is an array containing floats | for (float f:salaries)
Suppose a method called finallyTest() consists of a try block | If the JVM does
n t crash and
appropriate to pass a cause to an exception s constructor | thrown in response to
catching of a different exception type
Which of the following should always be caught | Checked exceptions
When does an exception s stack trace get recorded in the exception object | is c
onstructed
A dialog prevents user input to other windows in the application umtl the dialog
is closed | Modal
public float aMethod(float x. float y) {} | 1
Runtime Exception | 1
What is the output of the following code class Main { static intk- 10; static {k
?- 5;} public static void main(Strmg argsQ){ System outpnntln(k).}static {k 5;}
} | 20
Assuming any exception handling has been set up. which of the following will cre
ate an instance of the RandomAccessFile class? | RandomAccessFile raf-new Random
AccessFilefmyfile txr."rW)
How do you prevent shared data from being corrupted in a | Access the variables
only via synchronized mothods
Compile time error | 1
A thread's run() method includes the following lines 1 try{ 2 sleep(IOO);3.} c
atch (InterruptedException e) {} | At line 2. the thread will stop running It wi
ll resume running some time after 100 milliseconds have elapsed
When a user selects a menu,______is generated | Action event
When you compile a program written in the Java programming language, the compile
r converts the human-readable source file into platform-independent code that a
Java Virtual Machine can understand What is this platform-independent code calle
d? | bytecode
Which of the following operators can perform promotion on their operands? (Selec
t two) | + -
Select INCORRECT statement about FlowLayout | The Flow layout manager always hon
ors a component's preferred size D The Flow layout manager arranges components i
n horizontal rows
Which line contains only legal statements? | int x=6 x = ~x
Which Man class properly represents the relationship 'Man has the best friend wh
o is a Dog'? | class Man {private BestFnend dog;}
99 100 102 | 1
Select the most correct statement | A thread is in the ready state after it has
been created and started
Which of the following statements) is(are) true? 1)An abstract class can not hav
e any final methods 2)A final class may not have any abstract methods | Both sta
tement 1 and 2
What is the return type of the instanceof operator? | boolean
Study the statements: 1) When a JDBC connection is created, it is in auto
-commit mode 2) 0nce auto-commit mode is disabled, no SQL statements will be com
mitted until you call the method commit explicitly | both 1 and 2 are true
the code on line 29 will be executed | 1
No such file found. Doing finally.-1 | 1
Which of the following is true about Wrapped classes? | Wrapper classes are. Boo
lean. Char. Byte. Short. Integer. Long. Float and Double
Which of the followings statements is true? | The GndBagLayout manager is the de
fault manager for JFrame
What is the range of values that can be assigned to a variable of type short? |
2 mu 15 through 2 mu 15 -1
When is it appropriate to pass a cause to an exception's constructor? | When the
exception is being thrown in response to catching of a different exception type
Which of the statements below is true"? | When you construct an instance of File
, the file will not be created even if the corresponding file does not exist on
the local file system
Which of the following may follow the static keyword9 (Select two) | Methods and
Code blocks endosed in curly brackets
Which of the following statements is true | Constructors are not inherited
public interface B inheritsFrom A {} | 1
Which of the following statements is true | A for statement can loop infinitely,
for example for(;;);
Select INCORRECT statement about deserialize (choose 1) | We use readObjectO met
hod of ObjectOutputStream dass to deserialize
a#b, a==c | 1
Is it possible to define a dass called Thing so that the following method can re
turn true under certain drcumstances? boolean weirdfThing s) {Integer x = new ln
teger(5); return s.equals(x);} | yes
A(n)_____object is uses to obtain a Connection to a Database | DnverManager
Study the following Java statements:String sl= Hetlo ;String s2= Hello";String s3=
He
llo";String s4= new Stnng( Hello");How many strings, specified by the above code,
are stored in the memory of the program | 2
What is the difference between a TextArea and a TextField | A TextArea can handl
e multiple lines of text
You have been given a design document for a veterinary registration system for i
mplementation in Java. It states"A pet has an owner, a registration date, and a
vacdnation-due date A cat is a pet that has a flag indicating whether it has bee
n neutered, and a textual description of its markings"Given that the Pet class h
as already been defined, which of the following fields would be appropriate for
inclusion in the Cat class as members9 (Select the most appropriate two declarat
ions) | String markings boolean neutered;
A___dialog prevents user input to other windows in the application unitl the dia
log is closed.|Modal.
A value variable contains data's value.|True.
A reference variable contains the address of data.|True.
The Reader/Writer class hierarchy is character-oriented, and the InputStream/Out
putStream class hierarchy is byte-oriented.|True.
String s = new String("Bicycle"); int iBegin = 1; char iEnd = 3; System.out.prin
tln(s.substring(iBegin, iEnd));|Bic.
Which of the following layout manager will present components with the same size
.|java.awt.GridLayout.
Object references can be converted in both method calls and assignments, and the
rules goverming these conversions are identical.|True.
The Reader/Writer class hierarchy is character-oriented, and the InputStream/Out
putStream class hierarchy is byte-oriented.|True.
String s = new String("Bicycle"); int iBegin = 1; char iEnd = 3; System.out.prin
tln(s.substring(iBegin, iEnd));|Bic.
Which of the following layout manager will present components with the same size
.|java.awt.GridLayout.
Object references can be converted in both method calls and assignments, and the
rules goverming these conversions are identical.|True.
Which is four-step approach to help you organize your GUI thinking.|Identifi-Iso
late-Sketch-Choose.
Which statement is true about BorderLayout?.|...and the center of a container.
A program can suggest that garbage collection be performed but not force it.|Tru
e.
An object's lock is a mechanism that is used by multilple threads to obtain sync
hronized access to the object.|True.
Which statements about JDBC are NOT true?.|database system - any kind of DBMS.
Which of the following statements is true about two base protocols used for netw
orking TCP(Transmission Control Protocol) and UDP(User Datagram Protocol)?|TCP i
s a connection-based protocol and UDP is not connection-based protocol.
Which of the following is not a keyword or a reserved word in Java?.|Then.
MVC is short call of|Model-View-Controller.
How can you ensure that multithreaded code does not deadlock?|There is no single
technique that can guarantee non-deadlocking code.
If you need a Set implementation that provides value-ordered iteration, which ca
lss should you use?|TreeSet.
When is a thread in suspended state?|When wait() method is called.
Which of the following declarations is legal?|transient int i = 41;
Unicode characters are all 16 bits.|True.
Which of the following statements can be used to call a constructor of the super
class from its sub-class?|super();
Which of the following protocols is a connection-based protocol that provides a
reliable flow of data between two computers?|Transmission Control Protocol.
Which of the following statements about monitor is true?|A monitor is an instanc
e of any class that has synchronized code.
Interfaces cannnot have constructors|True.
__Drivers that use a pure Java client and communicate with a middleware server u
sing a database-independent protocol The middleware server then communicates the
client's requests to the data source.|Type 3.
The default type of the ResultSet object is __|TYPE_FORWARD_ONLY.
Suppose the declared type of x is a class, and the declared type of y is an inte
rface. When is the assignment x = y; legal?|When the type of x is Object.
A method in an interface can access class level variables|Incorrect.
double d = 1.2d;|legal.
How do you prevent shared data from being corrupted in a multilthreaded environm
ent?| Access the variables only via synchronized methods.
The Swing's list component(JList) can display text only.|Correct.
The Swing's label(JLabel) can present an image.|Correct.
Which of the following operations might throw an ArithmeticException?.|%.
Under no circumstances can a class be defined with the private modifier.|True.
Adding more classes via import statements will cause a performance overhead, onl
y import classes you actually use.|True.
Suppose class X contains the following method:|Public void doSomething(int a, fl
oat b){...}.
A protected method may only be accessed by classes of the same package or by sub
classes of the class in which it is declared.|Correct.
Vector does not allow duplicate elements.|Incorrect.
Which of the following is a valid argument to the DataInputStream constructor?|F
ileInputStream.
The___class is the primary class that has the driver information.|DriverManager.
Consider the following code developed in NetBeans.What does the thread t do?|The
program cause errors when it is compiled.
What is 7%-4?|3.
A signed data type has an equal number of non-zero positive and negative values
available.|False.
Both primitives and object references can be both converted and cast.|Correct.
Which of the following statements is true about two base protocols used for netw
orking :TCP(Transmission Control Protocol) and UDP(User Datagram Protocol)?|TCP
is a connection-base protocol and UDP is not connection-based protocol.
To check whether the file denoted by the abstract pathname is a driectory or not
call the isDirectory() method of the File class.|True.
Which of the following methods of the Collections class can be used to find the
largest value in a Vector?.|We don't need any method because elements in Vector
are automatically sorted. Therefore, the first element contains the maximum valu
e.
Select the correct statement which set the layout manager of a given frame to Fl
owLayoutManager.|setLayout(new FlowLayout());
Suppose salaries is an array containing floats.Which of the following are valid
loop control statements for processing each element of salaries?|for(float f.sal
aries);
String x = "Hello"; int y = 9; x=x+y;|Legal.
Whenever a method does not want to handle exceptions using the try block.the___i
s used.|throws.
You cannot call an enum's toString() method.|True.
Which is the four steps are used in working with JDBC?|Connect-Create-Look-Close
.
Which of the following methods of the java.io.File can be used to create a new f
ile?|createNewFile().
Give a string constructed by calling s = new String("xyzzy").which of the calls
modifies the string?|None of the others.
Which of the following statements is INCORRECT about a non-static synchronized m
ethod?|It cannot call to a static synchronized method of the current class.
How can you force garbage collection of an object?|Garbage collection cannot be
forced.
char c = \u1234;|Incorrect.
In RMI implementations, all methods, declared in the remote interface, must thro
w the __exception.|java.rmi.RemoteException.
What method of the java.io.File class can create a file on the hard drive?|creat
eNewFile().
BorderLayout is the default layout manager for every JFrame.|True.
1.A_dialog prevents user input to other windows in the application until the dia
log is closed|Model
2.how do you prevent shared data from being corrupted in a multithreaded environ
ment?|Access the variable only via synchronized methods
3.When a user selects a menu item,_is generated.|Action event
4.When you compile a program written in the Java programming language,the compil
er converts the human-readble soure file into platfom- independent code that a J
ava Virtual Machine can understand|bytecode
5.Which of the following operators can perform promotion on their operands?(sele
ct two)|+-
6.Which line contains only legal statements?|int x=6;x=~x
7.Which Man class properly represents the relationship "Man has the bestfriend w
ho is a Dog"?|class Man{private BestFriend dog;}
8.A thread is in the ready state after is has been created and started|most corr
ect
9.Which of the following statement(s) is(are) true?1) An abstract class can not
have any fianl methods.2)A final class may not have any abstract methods.|Only s
tatement2
10.Which is the return type of the instance of operator?|A boolean
11.Study the statements: 1) When a JDBC connection is created,it is auto-commit
mode.2) Once auto-commit mode is disabled, no SQL statements will be committed u
ntil you call the method commit explicity| Both 1 and 2 are not true
12.Which of the following is true about Wrapped classes?|Wrapper class are :Bool
ean,Char,Byte,Short,Interger,long,Float and Double
13.The GridBagLayout manager is the default manager for JFrame|true
14.What is the range of values that can be assigned to a variable of type short?
|-2^15 throught 2^15-1
15.When is it appropriate to pass a cause to an exception's constructor?|...in r
esponse to catching of a different exception type
16. When you construct an instance of File,the file will not be created even if
the corresponding file does not exist on the local file system|true
17.Which of the following may follow the static keyword?(select two)|Methods and
Non-inner class definitions
18.Constructors are not inherited|true
19.A for statement can loop infinitely, for example:for(;;)|true
20.We use readoject() method of ObjectOutputStream class to deserialize|INCORREC
T
21.A(n)_ object is used to obtain a Connection to a Database|DriverManager
22.What is the difference between a TextArea and a TextField?|A TextArea can han
dle multiple lines of text
23.A pet has an owner, a registration date;and a vaccination-duw date.Given that
the Pet class has already been defined|String markings and boolean neutered
Which of the following are valid declarations? Assume java.util.* is imported.|V
ector<Map>v Set<String>s Map<String, String>m;
You can determine all the keys in a Map in which of the following ways?|By gett
ing a Set object from the Map and iterating through it
What keyword is used to prevent an object from being serialized |transient
An abstract class can contain methods with declared bodies.|true
Select the order of access modifiers from least restrictive to most restrictive.
|public, protected, default, private
Which access modifier allows you to access method calls in libraries not create
d in Java?|native
Which of the following statements are true? (Select all that apply.)|A final ob
ject cannot be reassigned a new address in memory.
The keyword extends refers to what type of relationship?| is a
Which of the following keywords is used to invoke a method in the parent clas
s?|super
What is the value of x after the following operation is performed? x = 23 %
4;|3
Given the following code, what keyword must be used at line 4 in order to stop
execution of the for loop?|break
What method call is used to tell a thread that it has the opportunity to run?|
notify()
Assertions are used to enforce all but which of the following?|Exceptions
The developer can force garbage collection by calling System.gc().|False
Select the valid primitive data types. (Select all that apply.)|boolean char flo
at
How many bits does a float contain?|32
A StringBuffer is slower than a StringBuilder, but a StringBuffer is threadsafe.
|true
Select the list of primitives ordered in smallest to largest bit size represent
ation.|char, int, float, long
Which class provides locale-sensitive text formatting for date and time informat
ion?|java.text.DateFormat
The following line of code is valid. int x = 9; byte b = x;|false
Java arrays always start at index 1.|false
Which of the following statements accurately describes how variables are passe
d to methods?|Arguments that are primitive type are passed by value.
How do you change the value that is encapsulated by a wrapper class after you
have instan- tiated it?|None of the above.
Suppose you are writing a class that provides custom deserialization. The class
implements java.io.Serializable (and not java.io.Externalizable). What method s
hould imple- ment the custom deserialization, and what is its access mode?|priva
te readObject
A signed data type has an equal number of non-zero positive and negative value
s available.|false
If all three top-level elements occur in a source file, they must appear in whi
ch order?|Package declaration, imports, class/interface/enum definitions
How can you force garbage collection of an object?|Garbage collection cannot b
e forced.
What is the range of values that can be assigned to a variable of type short?|-2
^15 through 2^15 - 1
What is the range of values that can be assigned to a variable of type byte?|-2^
7 through 2^7 - 1
Suppose a source file contains a large number of import statements. How do the
imports affect the time required to compile the source file?|Compilation takes
slightly more time
Suppose a source file contains a large number of import statements and one cl
ass definition.How do the imports affect the time required to load the class?|
Class loading takes no additional time.
Which of the following are legal?|char c = \u1234 ;
After execution of the following code fragment, what are the values of the var
iables x, a, and b?|x = 13, a = 7, b = 8
Which of the following expressions results in a positive value in x?|int x = 1
; x = x >>> 5;
What is -8 % 5?|-3
What is 7 % -4?|3
Suppose ob1 and ob2 are references to instances of java.lang.Object. If (ob1 =
= ob2) is false, can ob1.equals(ob2) ever be true?|no
When a byte is added to a char, what is the type of the result?|int
When a short is added to a float, what is the type of the result?|float
Which of the following operations might throw an ArithmeticException?|none of t
hese
Which of the following operations might throw an ArithmeticException?|/
What is the return type of the instanceof operator?|A boolean
Which of the following may appear on the left-hand side of an instanceof opera
tor?|A reference
Which of the following may appear on the right-hand side of an instanceof operat
or? (Choose all that apply.)|A class,An interface
What is -50 >> 1?|-25
Which of the following statements is true?|A final class may not have any abstr
act methods
Which of the following statements is true?|Transient variables are not serializ
ed
Which modifier or modifiers should be used to denote a variable that should not
be written out as part of its class s persistent state? (Choose the shortest pos
sible answer.)|transient
Suppose class Supe, in package packagea, has a method called doSomething(). Supp
ose class Subby, in package packageb, overrides doSomething(). What access mod
es may Subby s version of the method have? (Choose all that apply.)|public prote
cted
Which of the following statements are true?|None of the above.
True or false: If class Y extends class X, the two classes are in different pack
ages, and class X has a protected method called abby(), then any instance of Y
may call the abby() method of any other instance of Y.|false
Which of the following statements are true?|A final class may not be extended.
Which of the following statements is correct? (Choose one.)|Both primitives and
object references can be both converted and cast.
Which of the following statements is true? (Choose one.)|and the rules governin
g these conversions are identical.
Which of the following may legally appear as the new type (between the parenthe
ses) in a cast operation?|All of the above
Suppose the declared type of x is a class, and the declared type of y is an inte
rface. When is the assignment x = y; legal?|When the type of x is Object
Suppose the type of xarr is an array of XXX, and the type of yarr is an array of
YYY. When is the assignment xarr = yarr; legal?|Sometimes
When is x & y an int? (Choose one).|Sometimes
What are the legal types for whatsMyType? short s = 10; whatsMyType = !s;|There
are no possible legal types.
When a negative long is cast to a byte, what are the possible values of the resu
lt?|All of the above
When a negative byte is cast to a long, what are the possible values of the resu
lt?|negative
What is the difference between the rules for method-call conversion and the rule
s for assignment conversion?|There is no difference; the rules are the same.
Suppose salaries is an array containing floats. Which of the following are vali
d loop control statements for processing each element of salaries?|for (float f
:salaries)
Suppose a method called finallyTest() consists of a try block, followed by a ca
tch block, followed by a finally block. Assuming the JVM doesn t crash and the cod
e does not execute a System.exit() call, under what circumstances will the fina
lly block not begin to execute?|If the JVM doesn t crash and the code does not exe
cute a System.exit() call, the finally block will always execute.
Which of the following are legal loop definitions? (Choose all that apply.)|Non
e of them are legal
Which of the following are legal argument types for a switch statement?|byte int
char
When is it appropriate to pass a cause to an exception s constructor?|being thrown
in response to catching of a different exception type
Which of the following should always be caught?|Checked exceptions
When does an exception s stack trace get recorded in the exception object?|When
the exception is constructed
When is it appropriate to write code that constructs and throws an error?|never
Which of the following statements are true? (Choose all that apply.)|new Outer(
).new Inner()new Outer().new Inner()
Suppose x and y are of type TrafficLightState, which is an enum. What is the bes
t way to test whether x and y refer to the same constant?|if (x == y)
Which of the following restrictions apply to anonymous inner classes?|They must
be defined inside a code block.
A thread wants to make a second thread ineligible for execution. To do this,
the first thread can call the yield() method on the second thread.|false
A monitor called mon has 10 threads in its waiting pool; all these waiting threa
ds have the same priority. One of the threads is thr1. How can you notify thr1
so that it alone moves from the Waiting state to the Ready state?|You cannot s
pecify which thread will get notified.
A Java monitor must either extend Thread or implement Runnable.|false
Which of the following methods in the Thread class are deprecated?|suspend() an
d resume()
Which of the following statements about threads is true?|Threads inherit the
ir priority from their parent thread.
Which of the following statements about the wait() and notify() methods is tr
ue?|The thread that calls wait() goes into the monitor s pool of waiting threads
.
Which of the following may not be synchronized?|classes
How many locks does an object have?|one
Is it possible to write code that can execute only if the current thread owns
multiple locks?|yes
Which of the following are true?|The JVM runs until there are no non-daemon thre
ads.
How do you prevent shared data from being corrupted in a multithreaded environme
nt?|Access the variables only via synchronized methods.
How can you ensure that multithreaded code does not deadlock?|A, B, and C do not
ensure that multithreaded code does not deadlock.
Suppose you want to create a custom thread class by extending java.lang.Thread
in order to provide some special functionality. Which of the following must you
do?|Override run().
Given a string constructed by calling s = new String( xyzzy ), which of the calls
mo
difies the string?|None of the above
Suppose you want to write a class that offers static methods to compute hyperbol
ic trigonometric functions. You decide to subclass java.lang.Math and provide t
he new functionality as a set of static methods. Which one statement is true ab
out this strategy?|subclass java.lang.Math
Which line of code tells a scanner called sc to use a single digit as a delimite
r?|sc.useDelimiter( \\d );
Given arrays a1 and a2, which call returns true if a1 and a2 have the same leng
th, and a1[i].equals(a2[i]) for every legal index i?|java.util.Arrays.equals(a1,
a2);
Which of the statements below are true? (Choose all that apply.)|Unicode charac
ters are all 16 bits.
Which of the statements below are true? (Choose all that apply.)|None of the ab
ove.
How do you use the File class to list the contents of a directory?|String[] co
ntents = myFile.list();
Suppose you are writing a class that will provide custom serialization. The clas
s implements java.io.Serializable (not java.io.Externalizable). What access mode
should the writeObject() method have?|private
is a set of java API for executing SQL statements.|JDBC
method is used to wait for a client to initiate communications.|accept()
drivers that are written partly in the Java programming language and pa
rtly in native code. These drivers use a native client library specific to the d
ata source to which they connect. Again, because of the native code, their porta
bility is limited.|Type 2
drivers that are pure Java and implement the network protocol for a spe
cific data source. The client connects directly to the data source.|Type 4
drivers that use a pure Java client and communicate with a middleware s
erver using a database-independent protocol. The middleware server then communic
ates the client's requests to the data source.|Type 3
drivers that implement the JDBC API as a mapping to another data access
API, such as ODBC. Drivers of this type are generally|Type 1
26. System.out.println(a.doit(4, 5));|Line 26 prints a to System.out.
1. public class A {
2. public void method1() {|The code on line 29 will be executed,The excepti
on will be propagated back to line 27.
IOException extends Exception StreamCorruptedException extends IOException Malfo
rmedURLException extends IOException|Bad URL,Doing finally part,Carrying on
1. try { 2. // assume s is previously defined 3. URL u = new URL(s);|Succ
ess,Doing finally part,Carrying on
public class Beta {|The code compiles and the output is 2.,If lines 16, 17 and 1
8 were removed, the code would compile and the output would be 2.,If lines 24, 2
5 and 26 were removed, the code would compile and the output would be 1.
10. public class ClassA { 11. public void methodA() {|An exception is thrown a
t runtime.
11. public class Bootchy {|third second first snootchy 420
A dialog prevents user input to other windows in the application unitl th
e dialog is closed.|Modal
1. FileOutputStream fos = new FileOutputStream("datafile");|Construct a FileInpu
tStream, passing the name of the file. Onto the FileInputStream, chain a DataInp
utStream, and call its readInt() method.|Construct a RandomAccessFile, passing t
he name of the file. Call the random access file s readInt() method.
A Java monitor must either extend Thread or implement Runnable.|False
A monitor called mon has 10 threads in its waiting pool; all these waiting threa
ds have the same priority. One of the threads is thr1. How can you notify thr1 s
o that it alone moves from the Waiting state to the Ready state? (Choose one.)|Y
ou cannot specify which thread will get notified.
A programmer needs to create a logging method that can accept an arbitrary numbe
r of arguments. For example, it may be called in these|public void logIt(String.
.. msgs)
A signed data type has an equal number of non-zero positive and negative values
available.|False
A thread wants to make a second thread ineligible for execution. To do this, the
first thread can call the yield() method on the second thread|False
A thread s run() method includes the following lines:|At line 2, the thread will s
top running. It will resume running some time after 100 milliseconds have elapse
d
A(n) object is used to submit a query to a database|Statement
A(n) object is uses to obtain a Connection to a Database|DriverManager
After execution of the following code fragment, what are the values of the varia
bles x, a, and b? 1. int x, a = 6, b = 7; 2. x = a++ + b++;|x = 13, a = 7, b = 8
10. public class Money {|Euro returns correct Country value.,Compilation fails b
ecause of an error at line 25.
Choose the valid identifiers from those listed here. (Choose all that apply.)|Bi
gOlLongStringWithMeaninglessName,$int,bytes,$1,finalist
1. public class SomeException {|Compilation of class B will fail. Compilation of
class A will succeed.
1. public class TestException extends Exception {|Line 46 will compile if the en
closing method throws a TestException.,Line 46 will compile if enclosed in a try
block, where TestException is caught.
1. class Q6 {|101
1. class Q7 {|12.3
1. public class Test extends Base {|Test t = new Test(1);,Test t = new Test(1, 2
);
1. public class Test extends Base { 2. public Test(int j) {|Base() { },Base(int
j, int k) { }
1. class Cruncher {|The code will compile and produce the following output: int
version.
1. public class Base { 2. public void method(int i) {|Value is 5This value
is 6
2. String[] stringarr = new String[50];|Line 6
1. public class Assertification {|The application must be run with the -enableas
sertions flag or another assertionenabling flag.,The args array must have one or
more elements.
1. StringBuffer sbuf = new StringBuffer();|After line 2 executes, the StringBuff
er object is eligible for garbage collection.
1. Cat sunflower;|The code will compile but will throw an exception at line 7, b
ecause the runtime class of wawa cannot be converted to type SwampThing.
1. Dog rover, fido;|The code will compile and run.
1. for (int i = 0; i < 2; i++) {|i = 0 j = 1,i = 0 j = 2,i = 1 j = 0,i = 1 j = 2
1. outer: for (int i = 0; i < 2; i++) {|i = 1 j = 0
1. Raccoon rocky;|Line 7 will not compile; an explicit cast is required to conve
rt a Washer to a SwampThing.
1. public class Outer {|a,b,c,e
int[] x = new int[25];|x[24] is 0,x.length is 25
Which of the following methods would be legal (individually) at line 2 in class
Test2? (Choose two)|public int aMethod(int a, int b) throws Exception {...},publ
ic float aMethod(float p, float q) {...}
Which of the following methods would be legal if added (individually) at line 4?
(Choose three.)|public int aMethod(int a, int b) { },public float aMethod(float
a, float b, int c) throws Exception { },private float aMethod(int a, int b, int
c) { }
11. public static Iterator reverse(List list) {|Compilation fails.
Given a string constructed by calling s = new String("xyzzy"), which of the call
s modifies the string? (Choose one.)|None of the above
Given arrays a1 and a2, which call returns true if a1 and a2 have the same lengt
h, and a1[i].equals(a2[i]) for every legal index i? (Choose one.)|java.util.Arra
ys.equals(a1, a2);
public class Xyz implements java.io.Serializable {|iAmPublic,iAmPrivate,iAmVolat
ile
1. class SuperDuper|line 3: private; line 8: protected
enum Spice { NUTMEG, CINNAMON, CORIANDER, ROSEMARY; }|Spice sp = Spice.NUTMEG; O
bject ob = sp;,Spice sp = Spice.NUTMEG; Object ob = (Object)sp;,Object ob = new
Object(); Spice sp = (Spice)ob;
15. public static void main(String[] args) {|Compilation fails.
Given a string constructed by calling s = new String("xyzzy"), which of the call
s modifies the string? (Choose one.)|None of the above
Given arrays a1 and a2, which call returns true if a1 and a2 have the same lengt
h, and a1[i].equals(a2[i]) for every legal index i? (Choose one.)|java.util.Arra
ys.equals(a1, a2);
List<String> names = new ArrayList<String>();|Iterator<String> iter = names.iter
ator();,for (String s:names)
12. void process() throws Exception { throw new Exception(); }|Compilation
fails because of an error in line 19.
boolean b1 = true; boolean b2 = false; if((x==4) && !b2)|2 3
2. String DEFAULT_GREETING = Hello World ;|public interface B extends A { }
10. abstract public class Employee {|public double getSalesAmount() { return 123
0.45; },protected double getSalesAmount() { return 1230.45; }
10. class MakeFile {|An exception is thrown at runtime.,Line 13 creates a File o
bject named d. ,Line 14 creates a File object named f.
What keyword is used to prevent an object from being serialized?|transient
An abstract class can contain methods with declared bodies.|True
Select the order of access modifiers from least restrictive to most restrictive.
|public, protected, default, private
Which access modifier allows you to access method calls in libraries not create
d in Java?|native
Which of the following statements are true? (Select all that apply.)|A final ob
ject cannot be reassigned a new address in memory.
The keyword extends refers to what type of relationship?| is a
Which of the following keywords is used to invoke a method in the parent clas
s?|super
Given the following code, what will be the outcome?f.add(1, 2);|The code does no
t compile.
What is the value of x after the following operation is performed?x = 23 % 4
;|3
Given the following code, what keyword must be used at line 4 in order to stop
execution of the for loop?|break
What method call is used to tell a thread that it has the opportunity to run?|
notify()
Given the following code, which of the results that follow would you expect?pack
age mail;|The code will not compile because of line 4.
Assertions are used to enforce all but which of the following?|Exceptions
The developer can force garbage collection by calling System.gc().|False
Select the valid primitive data types. (Select all that apply.)|boolean,char,flo
at
How many bits does a float contain?|32
What is the value of x after the following line is executed?x = 32 * (31 -
10 * 3);|32
A StringBuffer is slower than a StringBuilder, but a StringBuffer is threadsafe.
|True
Select the list of primitives ordered in smallest to largest bit size represent
ation.|char, int, float, long
Which class provides locale-sensitive text formatting for date and time informat
ion?|java.text.DateFormat
The following line of code is valid.int x = 9; byte b = x;|False
Which of the following code snippets compile?|i = 7;i = new (5);j = i; byte b
= 7;
What will be the output of the following code? StringTest| same will be printed ou
t to the console.
Java arrays always start at index 1.|False
Which of the following statements accurately describes how variables are passe
d to methods?|Arguments that are primitive type are passed by value.
How do you change the value that is encapsulated by a wrapper class after you
have instan- tiated it?|None of the above.
Suppose you are writing a class that provides custom deserialization.|private r
eadObject
A signed data type has an equal number of non-zero positive and negative value
s available.|False
Choose the valid identifiers from those listed here. (Choose all that apply.)|Bi
gOlLongStringWithMeaninglessName,$int,bytes,$1,finalist
Which of the following signatures are valid for the main() method entry point of
an application?|public static void main(String arg[]),(String[] args)
If all three top-level elements occur in a source file, they must appear in whi
ch order?|Package declaration, imports, class/interface/enum definitions.
Consider the following line of code: int[] x = new int[25];|x[24] is 0,x.lengt
h is 25
Consider the following application:|101
How can you force garbage collection of an object?|Garbage collection cannot b
e forced.
What is the range of values that can be assigned to a variable of type short?|-2
15 through 215 - 1
What is the range of values that can be assigned to a variable of type byte?|-27
through 27 - 1
Suppose a source file contains a large number of import statements. How do the
imports affect the time required to compile the source file?|Compilation takes
slightly more time.
How do the imports affect the time required to load the class?|Class loading t
akes no additional time.
Which of the following are legal import statements?|import java.util.Vector;imp
ort static java.util.Vector.*;
Which of the following may be statically imported? (Choose all that apply.)|Stat
ic method names,Static field names
Which of the following are legal? (Choose all that apply.)|int c = 0xabcd;int
d = 0XABCD;
Which of the following are legal? (Choose all that apply.)|double d = 1.2d;dou
ble d = 1.2D;
Which of the following are legal?|char c = \u1234 ;
Consider the following code:|After line 2 executes, the StringBuffer object is
eligible for garbage collection.
Which of the following are true? (Choose all that apply.)|Primitives are passed
by value.References are passed by value.
After execution of the following code fragment, what are the values of the var
iables x, a, and b?|x = 13, a = 7, b = 8
Which of the following expressions are legal? (Choose all that apply.)|int x =
6; if (!(x > 3)) {},int x = 6; x = ~x;
Which of the following expressions results in a positive value in x?|int x = 1
; x = x >>> 5;
Which of the following expressions are legal? (Choose all that apply.)|String x
= "Hello"; int y = 9; x += y;int y = 9; x = x + y;
What is -8 % 5?|-3
What is 7 % -4?|3
What results from running the following code?class Xor|The output: b contains
5
What results from attempting to compile and run the following code?Conditional|T
he output: value is 9.0
What does the following code do?|Throws an exception.
Suppose ob1 and ob2 are references to instances of java.lang|No
When a byte is added to a char, what is the type of the result?|int
When a short is added to a float, what is the type of the result?|float
int selfXor(int i) { return i ^ i;|A. It always returns 0.
Which of the following operations might throw an ArithmeticException?|None of t
hese
Which of the following operations might throw an ArithmeticException?|/
What is the return type of the instanceof operator?|A boolean
Which of the following may appear on the left-hand side of an instanceof opera
tor?|A reference
Which of the following may appear on the right-hand side of an instanceof operat
or? (Choose all that apply.)|A class,An interface
What is -50 >> 1?|-25
Which of the following statements is true?|A final class may not have any abstr
act methods.
What is the minimal modification that will make this code compile correctly?fina
l class Aaa|On line 1, remove the final modifier.
Which of the following statements is true?|Transient variables are not serializ
ed.
Which statement is true about this application?class StaticStuff|The code compi
les and execution produces the output x = 3.
Which statement is true about this code?class HasStatic|The program compiles an
d the output is x = 104.
class SuperDuper|line 3: private; line 8: protected
Which modifier or modifiers should be used to denote a variable that should not
be written out as part of its class s persistent state?|transient
This question concerns the following class definition:|The program will compile
and execute. The output will be Before: 0 After: 2.
Suppose class Supe, in package packagea, has a method called doSomething()|publi
c,protected
Which of the following statements are true?|None of the above.
Which of the following may be declared final? (Choose all that apply.)|Classes,D
ata,Methods
class MakeFile {|An exception is thrown at runtime.,Line 13 creates a File objec
t named d. ,Line 14 creates a File object named f.
12. public int fubar( Foo foo) { return foo.bar(); }|new Foo() { public int
bar(){return 1; } }
10. public class ClassA { 11. public void count(int i) {|StackOverflowError
11. public abstract class Shape {|Shape s = new Circle(); s.setAnchor(10,10); s.
draw();
11. public static void main(String[] args) {|1 2 3
11. public static void main(String[] args) { 12. try {|Compilation fails.
11. public static void parse(String str) {|Compilation fails.
11. String test = This is a test ;|Compilation fails.
12. public class AssertStuff {|passed An AssertionError is thrown with the word s
tuff added to the stack trace.
12. public class Test { 13. public enum Dogs {collie, harrier};|collie harri
er
13. public class Pass {|doStuff x = 5 main x = 5
20. public class CreditCard {|The ownerName variable breaks encapsulation.
23. Object [] myObjects = {|Compilation fails due to an error in line 29.
31. // some code here|The code on line 33 throws an exception.,The code on line
35 throws an exception.,The code on line 31 throws an exception.
35. }catch (NullPointerException e1) {|ac
55. int []x= {1, 2,3,4, 5};|Line 57 will print the value 3.
10. assert a.length == 1;|java -ea test,java -ea test file1 file2
1. public class TestString3 {|StringBuffer s = new StringBuffer( 123456789 );
s.dele
te(0,3).replace( 1,3, 24 ).delete(4,6);,StringBuilder s = new
StringBuilder( 12345678
9 ); s.delete(0,3).delete( 1 ,3).delete(2,5).insert( 1, 24 );
10. class Line {|Line.Point p = new Line.Point();
10. public class Bar { 11. static void foo(int...x) {|for(int z : x) System
.out.println(z);,for( int i=0; i< x.length; i++ ) System.out.println(x[i]);
12. /* insert code here */ int MY_VALUE = 10;|final,static,public
catch (Exception e) { System.out.print("Exception "); }|A Exception
How can you ensure that multithreaded code does not deadlock? (Choose one.)|Ther
e is no single technique that can guarantee non-deadlocking code.
How can you force garbage collection of an object? (Choose one.)|Garbage collect
ion cannot be forced.
How do you prevent shared data from being corrupted in a multithreaded environme
nt? (Choose one.)|Access the variables only via synchronized methods.
How do you use the File class to list the contents of a directory? (Choose one.)
|String[] contents = myFile.list();
2. FileOutputStream fos = newFileOutputStream("dest");|8
How many locks does an object have? (Choose one.)|One
If all three top-level elements occur in a source file, they must appear in whic
h order? (Choose one.)|Package declaration, imports, class/interface/enum defini
tions.
If class Y extends class X, the two classes are in different packages, and class
X has a protected method called abby(), then any instance of Y may call the abb
y() method of any other instance of Y.|False
1. class TestThread3 extends Thread {|Yes
If you need a Set implementation that provides value-ordered iteration, which cl
ass should you use? (Choose one.)|TreeSet
In order for objects in a List to be sorted, those objects must implement which
interface and method? (Choose one.)|Comparable interface and its compareTo meth
od.
1. StringBuffer sbuf = new StringBuffer("FPT");|True
1. byte b = 11; 2. short s = 13; 3. result = b * ++s;|int, long, float, double
Interface helps manage the connection between a Java program and a databa
se.|Connection
boolean weird(Thing s) { Integer x = new Integer(5); return s.equals(x);|Yes
Is it possible to write code that can execute only if the current thread owns mu
ltiple locks?|Yes
JDBC supports and models.|Two-tier and three-tier
MVC is short call of|Model-View-Controller
byte b = 2; byte b1 = 3; b = b * b1;|No output because of compile error at line:
b = b * b1;
public static void main(String[] args){ Object ob1= new Object(); Object ob2= ne
w Object();|Have a nice day!
public static void main(String[] args){ Object ob1= new Object(); Object ob2= ob
1;|ob1 equals ob2,ob1==ob2,Have a nice day!
if (s1 == s2) System.out.println("Line 4"); if (s1.equals(s2)) System.out.printl
n("Line 6");|Line 4 Line 6
public static void main(String[] args){ String s1 = "xyz";|Line 6
if (s1.equals(s2)) System.out.println("Line 6");|Line 6
s2=s2.intern();|Line 4 Line 6
Select correct statement about RMI. (choose 1)|All the above
Select correct statement(s) about remote class.(choose one)|All the others choic
es
Select correct statements about remote interface. (choose 1)|All the others choi
ces
Select INCORRECT statement about serialization. (choose 1)|When an Object Outpu
t Stream serializes an object that contains references to another object, every
referenced object is not serialized along with the original object.
Select INCORRECT statement about deserialize. (choose 1)|We use readObject() met
hod of ObjectOutputStream class to deserialize.
Select incorrect statement about RMI server.(choose 1)|A client accesses a remot
e object by specifying only the server name.
Select incorrect statement about ServerSocket class. (choose 1)|To make the new
object available for client connections, call its accept() method, which returns
an instance of ServerSocket
Select incorrect statement about Socket class. (choose 1)|The java.net.Socket cl
ass contains code that knows how to find and communicate with a server through U
DP.
Select the correct statement about JDBC two-tier processing model.|A user's comm
ands are delivered to the database or other data source, and the results of thos
e statements are sent back to the user.
SQL keyword is followed by the selection criteria that specify the rows to
select in a query|WHERE
Statement objects return SQL query results as objects|ResultSet
2)Once auto-commit mode is disabled, no SQL statements will be committed until y
ou call the method commit explicitly|Both 1 and 2 are true
Suppose a method called finallyTest() consists of a try block, followed by a cat
ch block, followed by a finally block. Assuming the JVM doesn t crash and the code
does not execute a System.exit() call, under what circumstances will the finall
y block not begin to execute? (Choose one.)|If the JVM doesn't crash and the cod
e does not execute a System.exit() call, the finally block will always execute.
Suppose a source file contains a large number of import statements and one class
definition. How do the imports affect the time required to load the class? (Cho
ose one.)|Class loading takes no additional time.
Suppose a source file contains a large number of import statements. How do the i
mports affect the time required to compile the source file? (Choose one.)|Compil
ation takes slightly more time.
Suppose class A extends Object; Class B extends A; and class C extends B. Of the
se, only class C implements java.io.Externalizable. Which of the following must
be true in order to avoid an exception during deserialization of an instance of
C? (Choose one.)|C must have a no-args constructor.
Suppose class A extends Object; class B extends A; and class C extends B. Of the
se, only class C implements java.io.Serializable. Which of the following must be
true in order to avoid an exception during deserialization of an instance of C?
(Choose one.)|B must have a no-args constructor.
Suppose class A has a method called doSomething(), with default access. Suppose
class B extends A and overrides doSomething(). Which access modes may not apply
to B s version of doSomething()? (Choose one)|private
Suppose class Supe, in package packagea, has a method called doSomething(). Supp
ose class Subby, in package packageb, overrides doSomething(). What access modes
may Subby s version of the method have? (Choose two.)|public,protected
void doSomething(int a, float b) { }|public void doSomething(int a, float b) {
}
Suppose interface Inty defines five methods. Suppose class Classy declares|The c
lass will compile if it is declared abstract.,The class may not be instantiated.
Suppose prim is an int and wrapped is an Integer. Which of the following are leg
al Java statements? (Choose one.)|All the above
Suppose salaries is an array containing floats. Which of the following are valid
loop control statements for processing each element of salaries? (Choose one.)|
for (float f:salaries)
Suppose the declared type of x is a class, and the declared type of y is an inte
rface. When is the assignment x = y; legal? (Choose one.)|When the type of x is
Object
Suppose the type of xarr is an array of XXX, and the type of yarr is an array of
YYY. When is the assignment xarr = yarr; legal? (Choose one.)|Sometimes
Suppose x and y are of type TrafficLightState, which is an enum. What is the bes
t way to test whether x and y refer to the same constant? (Choose one.)|if (x ==
y)
The class implements java.io.Serializable (not java.io.Externalizable). What acc
ess mode should the |private
Suppose you want to create a custom thread class by extending java.lang.Thread i
n order to provide some special functionality. Which of the following must you d
o? (Choose one.)|Override run().
Suppose you want to write a class that offers static methods to compute hyperbol
ic trigonometric |The strategy fails because you cannot add static methods to a
subclass.
Swing components cannot be combined with AWT components.|True
The class is the primary class that has the driver information.|DriverManag
er
class is used to implement a pull-down menu that provides a number of items to s
elect from.|Menu
The element method alters the contents of a Queue.|False
The Swing component classes can be found in the package.|javax.swing
There are two classes in Java to enable communication using datagrams namely.|Da
taPacket and DataSocket
6. protected void fly() { /* Flap wings, etc. */ }|Compilation of Parrot.ja
va fails at line 7 because method getRefCount() is static in the superclass, and
static methods may not be overridden to be nonstatic.
3. class Nightingale extends abcde.Bird {|The program will compile and execute.
The output will be Before: 0 After: 2.
This question involves IOException, AWTException, and EOFException.|void doSomet
hing() { },void doSomething() throws EOFException { },void doSomething()
throws
IOException, EOFException { }
URL referring to databases use the form:|protocol:subprotocol:datasoursename
What are the legal types for whatsMyType? (Choose one.) short s = 10;|There are
no possible legal types.
if (i != null & i.intValue() == 5) System.out.println("Value is 5");|Throws an e
xception.
1. FileOutputStream fos = new FileOutputStream("xx");|The output is i = 20.
that1.x = 5; that2.x = 1000; x = -1;|-1
3. public class Xxx {|An exception is thrown at line 9.
public static void main(String[] args) { System.out.println(">>" + s + "<<");|Th
e code compiles, and prints out >>null<<
5. Set<Apple> set = new TreeSet<Apple>();|An exception is thrown at line 7.
What is -50 >> 2|-13
What is 7 % -4?|3
What is -8 % 5?|-3
What is the difference between the rules for method-call conversion and the rule
s for assignment conversion? (Choose one.)|There is no difference; the rules are
the same.
1. final class Aaa|On line 1, remove the final modifier.
What is the range of values that can be assigned to a variable of type byte? (Ch
oose one.)|-2^7 through 2^7 - 1
What is the range of values that can be assigned to a variable of type short? (C
hoose one.)|-2^15 through 2^15 - 1
4. BufferedOutputStream bos = new BufferedOutputStream(raf);|The code fails
to compile.
What is the return type of the instanceof operator?|A boolean
What method of the java.io.File class can create a file on the hard drive? (Choo
se one.)|createNewFile()
4. System.out.println("value is " + ((x > 4) ? 99.99 : 9));|The output: va
lue is 9.0
3. byte b = 10; // 00001010 binary|The output: b contains 5
1. int x = 0, y = 4, z = 5;|message four
When a byte is added to a char, what is the type of the result?|int
When a negative byte is cast to a long, what are the possible values of the resu
lt? (Choose one.)|Negative
When a negative long is cast to a byte, what are the possible values of the resu
lt? (Choose one.)|All the above
When a short is added to a float, what is the type of the result?|float
When comparing java.io.BufferedWriter to java.io.FileWriter, which capability ex
ists as a method in only one of the two? (Choose one.)|writing a line separator
to the stream
When does an exception's stack trace get recorded in the exception object? (Choo
se one.)|When the exception is constructed
When is it appropriate to pass a cause to an exception's constructor? (Choose on
e.)|When the exception is being thrown in response to catching of a different ex
ception type
When is it appropriate to write code that constructs and throws an error? (Choos
e one.)|Never
When is x & y an int? (Choose one).|Sometimes
When the user attempts to close the frame window, event in generated.|win
dow closing
When the user selects a menu item, event is generated.|Action event
When you compile a program written in the Java programming language,|bytecode
Whenever a method does not want to handle exceptions using the try block, the
is used.|throws
Which are the correct statements used for getting connection object to connect t
o SQL Server database?|String url ="jdbc:odbc:data_source_name"; Connection con
= DriverManager.getConnection (url, user", "password");
Which class and static method can you use to convert an array to a List? (Choose
one.)|Arrays.asList
Which is four-step approach to help you organize your GUI thinking. (Choose one.
)|Identify needed components. Isolate regions of behavior. Sketch the GUI. Choos
e layout managers.
Which is the four steps are used in working with JDBC?|1)Connect to the database
,2)Create a statement and execute the query,3)Look at the result set,4)Close con
nection
Which JDBC processing model that requires a JDBC driver that can communicate wi
th the particular data source being accessed?|two-tier
Which line of code tells a scanner called sc to use a single digit as a delimite
r? (Choose one.)|sc.useDelimiter("\\d");
Which Man class properly represents the relationship "Man has the best friend wh
o is a Dog"? (Choose one.)|class Man { private Dog bestFriend; }
Which methods return an enum constant s name? (Choose two.)|name().,toString()
Which modifier or modifiers should be used to denote a variable that should not
be written out as part of its class's persistent state? (Choose the shortest pos
sible answer.)|transient
Which of the following are legal argument types for a switch statement? (Choose
three.)|byte,int,char
Which of the following are legal import statements? (Choose two.)|import java.ut
il.Vector;,import static java.util.Vector.*;
Which of the following are legal loop constructions? (Choose one.)|for (int k=0,
j+k != 10; j++,k++) { System.out.println("j=" + j + ", k=" + k);
Which of the following are legal loop definitions? (Choose one.)|None of the abo
ve.
Which of the following are legal? (Choose three.)|for (int i=0, j=1; i<10; i++,
j++),for (int i=0, j=1;; i++, j++),for (String s = ""; s.length()<10; s += '!')
Which of the following are legal? (Choose two.)|double d = 1.2d;,double d = 1.2D
;
Which of the following are legal? (Choose two.)|int c = 0xabcd;,int d = 0XABCD;
Which of the following are legal? (Choose two.)|char c = 0x1234;,char c = '\u123
4';
Which of the following are legal? (Choose two.)|List<String> theList = new Vecto
r<String>();,Vector <String> theVec = new Vector<String>();
Which of the following are methods of the java.util.SortedMap interface? (Choose
three.)|headMap,tailMap,subMap
Which of the following are methods of the java.util.SortedSet interface? (Choose
one.)|All the above
Which of the following are true? (Choose one.)|All the above
Which of the following are true? (Choose one.)|The JVM runs until there are no n
on-daemon threads.
Which of the following are true? (Choose three.)|When an application begins runn
ing, there is one non-daemon thread, whose job is to execute main().,A thread cr
eated by a daemon thread is initially also a daemon thread.,A thread created by
a non-daemon thread is initially also a non-daemon thread.
Which of the following are true? (Choose two.)|When you declare a method to be s
ynchronized, the method always synchronizes on the lock of the current object.,W
hen you declare a block of code inside a method to be synchronized, you can spec
ify the object on whose lock the block should synchronize.
Which of the following are true? (Choose two.)|An enum may contain public method
definitions.,An enum may contain private data.
Which of the following are true? (Choose two.)|Primitives are passed by value.|R
eferences are passed by value.
Which of the following are true? (Choose two.)|An anonymous inner class may impl
ement at most one interface,An anonymous inner class may extend a parent class o
ther than Object.
Which of the following are valid arguments to the DataInputStream constructor? (
Choose one.)|FileInputStream
Which of the following are valid mode strings for the RandomAccessFile construct
or? (Choose one.)|All the above
Which of the following calls may be made from a non-static synchronized method?
(Choose one.)|All the above
Which of the following classes implement java.util.List? (Choose two.)|java.util
.ArrayList,java.util.Stack
Which of the following classes implements a FIFO Queue? (Choose one.)|LinkedLis
t
Which of the following declarations are illegal? (Choose three.)|default String
s;,abstract double d;,abstract final double hyperbolicCosine();
Which of the following expressions are legal? (Choose two.)|int x = 6; if (!(x >
3)) {},int x = 6; x = ~x;
Which of the following expressions are legal? (Choose two.)|String x = "Hello";
int y = 9; x += y;,String x = "Hello"; int y = 9; x = x + y;
Which of the following expressions results in a positive value in x? (Choose one
.)|int x = 1; x = x >>> 5;
Which of the following interfaces does not allow duplicate objects? (Choose one.
)|Set
Which of the following is not appropriate situations for assertions? (Choose one
)|Preconditions of a public method
Which of the following is NOTa valid comment:|/* comment
Which of the following is the most appropriate way to handle invalid arguments i
n a public method?|Throw java.lang.IllegalArgumentException.
Which of the following is true? (Choose one.)|Readers have methods that can read
and return floats and doubles.-->None of the above
An enum definition may contain the main() method of an application.|All the abov
e
Which of the following may appear on the left-hand side of an instanceof operato
r?|A reference
Which of the following may appear on the right-hand side of an instanceof operat
or? (Choose two.)|A class,An interface
Which of the following may be statically imported? (Choose two.)|Static method n
ames,Static field names
Which of the following may follow the static keyword? (Choose three.)|Data,Metho
ds,Code blocks enclosed in curly brackets
Which of the following may legally appear as the new type (between the parenthes
es) in a cast operation? (Choose one.)|All of the others
Abstract classes|All of the above
Which of the following may not be synchronized? (Choose one.)|Classes
Which of the following may override a method whose signature is void xyz(float f
)? (Choose two.)|void xyz(float f),public void xyz(float f)
Which of the following methods in the Thread class are deprecated? (Choose one.)
|suspend() and resume()
Which of the following operations might throw an ArithmeticException? (Choose on
e.)|None of these
Which of the following operations might throw an ArithmeticException? (Choose on
e.)|/
Which of the following operators can perform promotion on their operands? (Choos
e three.)|+ - ~
Which of the following restrictions apply to anonymous inner classes? (Choose on
e.)|They must be defined inside a code block.
Which of the following should always be caught? (Choose one.)|Checked exceptions
Which of the following signatures are valid for the main() method entry point of
an application? (Choose two.)|public static void main(String arg[]),public stat
ic void main(String[] args)
Which of the following statements about the wait() and notify() methods is true?
(Choose one.)|The thread that calls wait() goes into the monitor s pool of waitin
g threads.
Which of the following statements about threads is true? (Choose one.)|Threads i
nherit their priority from their parent thread.
Which of the following statements are true? (Choose one.)|A final class may not
be extended.
Which of the following statements are true? (Choose one.)|new Outer().new Inner(
)
An abstract class may be instantiated.|None of the above
Which of the following statements are true? (Choose two.)|StringBuilder is gener
ally faster than StringBuffer.,StringBuffer is threadsafe; StringBuilder is not.
1)An abstract class may not have any final methods.|Only statement 2
Which of the following statements is correct? (Choose one.)|Both primitives and
object references can be both converted and cast.
Which of the following statements is true? (Choose one.)|Transient variables are
not serialized.
Which of the following statements is true? (Choose one.)|Object references can b
e converted in both method calls and assignments, and the rules governing these
conversions are identical.
Which of the statements below are true? (Choose one.)|Unicode characters are all
16 bits.
To change the current working directory, call the setWorkingDirectory() method o
f the File class.|None of the above
When you construct an instance of File, if you do not use the file-naming|None o
f the above.
1. byte b = 5; 2. char c = 5 ;|Line 6
1. class HiPri extends Thread {|None of the above scenarios can be guaranteed to
happen in all cases.
3. System.out.println("cosine of 0.123 = " + myMath.cos(0.123));|Compilation fa
ils at line 2.
1. String s = "FPT"; 2. StringBuffer s1 = new StringBuffer("FPT"); 3. if (s.equa
ls(s1)) 4. s1 = null;|Compilation succeeds. No exception is thrown during e
xecution.
1. String s1 = "abc" + "def";|Line 6 executes and line 4 does not.
1. class Greebo extends java.util.Vector implements Runnable {|There will be a
compiler error, because class Greebo does not correctly implement the Runnable i
nterface.
2. switch (j) {|The output would be the text value is two followed by the text v
alue is three.
int selfXor(int i) {|int selfXor(int i) {
1. class StaticStuff|The code compiles and execution produces the output x = 3.
1. class HasStatic|The program compiles and the output is x = 104.
Which statements about JDBC are NOT true? (choose 2)|JDBC is a Java database sy
stem.,JDBC is a Java API for connecting to any kind of DBMS
Which two code fragments correctly create and initialize a static array of int
elements? (Choose two.)|static final int[] a = { 100,200 };,static final int[] a
; static { a=new int[2]; a[0]=100; a[1]=200; }
Which two of the following interfaces are at the top of the hierarchies in the J
ava Collections Framework? (Choose two.)|Map,Collection
2. File f2 = new File(f1, "filename");|No directory is created, and no file is c
reated.
"A pet has an owner, a registration date, and a vaccination-due date. A cat|publ
ic class Cat extends Pet
Given that the Pet class has already been defined, which of the following fields
would be appropriate for inclusion in the Cat class as members? (Choose two.)|b
oolean neutered;,String markings;
Suppose class A has a method called doSomething(), with default access|public,p
rotected,Default
True or false: If class Y extends class X|False
Which of the following statements are true?|A final class may not be extended.
What does the following code print? public class A|-1
Which of the following statements is correct? (Choose one.)|Both primitives and
object references can be both converted and cast.
Which one line in the following code will not compile? byte b = 5;|Line 6
In the following code, what are the possible types for variable result? (Choose
the most complete true answer.)|int, long, float, double
class Cruncher|The code will compile and produce the following output: int ver
sion.
Which of the following statements is true? (Choose one.)|Object references can
be converted in both method calls and assignments, and the rules governing the
se conversions are identical.
1. Object ob = new Object();|Line 6
1. Cat sunflower;|wawa cannot be converted to type SwampThing.
1. Raccoon rocky;|Line 7 will not compile; an explicit cast is required
to convert a Washer to a SwampThing.
Which of the following may legally appear as the new type (between the parenthe
ses) in a cast operation?|All of the above
Suppose the declared type of x is a class, and the declared type of y is an inte
rface. When is the assignment x = y; legal?|When the type of x is Object
Suppose the type of xarr is an array of XXX, and the type of yarr is an array of
YYY. When is the assignment xarr = yarr; legal?|Sometimes
What are the legal types for whatsMyType?|There are no possible legal types.
When a negative long is cast to a byte, what are the possible values of the resu
lt?|All of the above
When a negative byte is cast to a long, what are the possible values of the resu
lt?|Negative
Which of the following operators can perform promotion on their operands? (Choo
se all that apply.)|+,-,~
What is the difference between the rules for method-call conversion and the rule
s for assignment conversion?|There is no difference; the rules are the same.
for (int i = 0; i < 2; i++) {|i = 0 j = 1,i = 0 j = 2,i = 1 j = 0,i =
1 j = 2
outer: for (int i = 0; i < 2; i++) {|i = 1 j = 0
int x = 0, y = 4, z = 5;|message four
int j = 2;|The output would be the text value is two followed by the text value
is three.
Which of the following is the most appropriate way to handle invalid arguments
in a public method?|Throw java.lang.IllegalArgumentException.
Suppose salaries is an array containing floats. Which of the following are vali
d loop control statements for processing each element of salaries?|for (float f
:salaries)
Suppose a method called finallyTest() consists of a try block|If the JVM
Which of the following are legal loop definitions? (Choose all that apply.)|Non
e of them are legal.
Which of the following are legal argument types for a switch statement?|byte,int
,char
When is it appropriate to pass a cause to an exception s constructor?|B.
When the
exception is being thrown in response to catching of a different exception ty
pe
Which of the following should always be caught?|Checked exceptions
When does an exception s stack trace get recorded in the exception object?|When
the exception is constructed
When is it appropriate to write code that constructs and throws an error?|Never
public class Test1 {|public int,throws Exception,private
What output results when the main method of the class Sub is run?|Value is 5
This value is 6
public class Test extends Base {|Test t = new Test(1);Test t = new Test(1, 2
);
1. public class Outer {|a,b,c,e
Which of the following may override a method whose signature is void xyz(float
f)?|void xyz(float f),public void xyz(float f)
Which of the following are true? (Choose all that apply.)|An enum may contain p
ublic method definitions.data.
Suppose x and y are of type TrafficLightState, which is an enum|if (x == y)
Which of the following restrictions apply to anonymous inner classes?|They must
be defined inside a code block.
Which methods return an enum constant s name?|name(),toString()
void doSomething(int a, float b) { }|public void doSomething(int a, float
b) { }
Which of the following statements about the wait() and notify() methods is tr
ue?|The thread that calls wait() goes into the monitor s pool of waiting threads
.
Which of the following may not be synchronized?|Classes
How many locks does an object have?|One
Is it possible to write code that can execute only if the current thread owns
multiple locks?|Yes
Which of the following are true?|The JVM runs until there are no non-daemon thre
ads.
How do you prevent shared data from being corrupted in a multithreaded environme
nt?|Access the variables only via synchronized methods.
How can you ensure that multithreaded code does not deadlock?|A, B, and C do not
ensure that multithreaded code does not deadlock.
Suppose you want to create a custom thread class by extending java.lang.Thread
|Override run().
Given a string constructed by calling s = new String( xyzzy ), which of the calls
mo
difies the string?|None of the above
Suppose you want to write a class that offers static methods to compute hyperbol
ic trigonometric functions|The strategy fails because you cannot subclass java.
lang.Math
import java.lang.Math;|Compilation fails at line 2.
String s = abcde ;|Compilation succeeds. No exception is thrown during execution.
sbuf.insert(3, xyz );|True
Which of the following are methods of the java.util.SortedMap interface?|headMa
p,tailMap,subMap
Which line of code tells a scanner called sc to use a single digit as a delimite
r?|sc.useDelimiter( \\d );
Set<Apple> set = new TreeSet<Apple>();|An exception is thrown at line 7.
Given arrays a1 and a2, which call returns true if a1 and a2 have the same leng
th, and a1[i].equals(a2[i]) for every legal index i?|java.util.Arrays.equals(a1,
a2);
Which of the following statements are true?|StringBuilder is not,StringBuffer.
Which of the statements below are true? (Choose all that apply.)|Unicode charac
ters are all 16 bits.
Which of the statements below are true? (Choose all that apply.)|None of the ab
ove.
How do you use the File class to list the contents of a directory?|String[] co
ntents = myFile.list();
FileOutputStream fos = newFileOutputStream( dest );|12
What does the following code fragment print out at line 9?The output is i = 20.
FileOutputStream fos = new FileOutputStream( datafile );|Construct a
FileInputStream
,Construct a RandomAccessFile
Which of the following is true?|None of the above.
File f1 = new File( dirname );|No directory is created, and no file is created.
BufferedOutputStream bos = new|The code fails to compile
What access mode should the writeObject() method have?|private
What access mode should the readObject() method have?|private
java.io.Serializable|B must have a no-args constructor.
java.io.Externalizable|C must have a no-args constructor.
public class Xyz implements java.io.Serializable|iAmPublic,iAmPrivate,iAmVolatil
e
What method of the java.io.File class can create a file on the hard drive?|crea
teNewFile()
File f = new File("xxx.ser");|An exception is thrown at line 9.
Which of the following are valid mode strings for the RandomAccessFile construct
or? (Choose all that apply.)| r , rw , rws , rwd
Which of the following are valid arguments to the DataInputStream constructor?|
FileInputStream
public void eee() { }|b,d,fff()
public abstract class Abby|SubAbby generates a compiler error.,If,variables.
int[] heights = new int[10];|heights is initialized to a reference to an array
with zero elements.
Given a class with a public variable theTint of type Color, which of the followi
ng methods are consistent with the JavaBeans naming standards?|public Color get
TheTint()
void callMe(String names) { }|Within the method, names is an array containing
Strings.
public class Food { }|Fruit,Citrus,Pomelo
class A extends java.util.Vector { private A(int x)|The compiler does not cre
ate a default constructor.
Which of the following types are legal arguments of a switch statement?|enums,b
ytes
int[] ages = { 9, 41, 49 }; int sum = 0;|for (int i=0; i<ages.length; i++),f
or (int i:ages) sum += i;
Which lines check that x is equal to four? Assume assertions are enabled at com
pile time and runtime.|assert x == 4;assert x == 4 : x is not 4 ;
Which are appropriate uses of assertions?|Checking preconditions in a private me
thod,Checking postconditions
EOFException and ObjectStreamException both extend IOException|void callMe(),C.
void callMe() throws NotSerializableException
try { callMe();|Object Stream,Finally
While testing some code that you are developing, you notice that an ArrayIndexO
utOf- BoundsException is thrown.|None of the above.
How is IllegalArgumentException used? (Choose all correct options.)|public metho
ds have been violated.preconditions have been violated.
Which of the following statements are true? (Choose all correct options.)|Strin
gBuilder encapsulates a mutable string.StringBuffer is threadsafe.
Suppose you want to read a file that was not created by a Java program|Create a
FileReader instance. Pass it into the constructor of LineNumberReader. Use Line
NumberReader s readLine() method.
What interfaces can be implemented in order to create a class that can be serial
ized? (Choose all that apply.)|interface.readExternal and writeExternal
The class implements java.io.Serializable (not java.io.Externalizable)|private
Suppose you want to use a DateFormat to format an instance of Date|The style, w
hich is one of SHORT, MEDIUM, LONG, or FULL,The locale
How do you generate a string representing the value of a float f in a format a
ppropriate for a locale loc?|NumberFormat nf = NumberFormat.getInstance(loc);
String scanMe = aeiou9876543210AEIOU ;|String delim = \\d+ ;
Which line prints double d in a left-justified field that is 20 characters wide,
with 15 characters to the right of the decimal point?|System.out.format("%-20.1
5f", d);
Suppose MyThread extends java.lang.Thread, and MyRunnable implements java.lang.
Runnable|(new MyThread()).start();(new Thread(new MyRunnable()))
try { sleep(5000);|The code prints Going to sleep, then Waking up, and then
All do
ne.
sharedOb.wait();|aThread.interrupt();sharedOb.notifyAll();
Suppose class Home has methods chopWood() and carryWater();|inappropriate cohes
ion.inappropriate coupling.
Lemon lem = new Lemon(); Citrus cit = new Citrus();|cit = lem;lem = (Lemon)c
it;cit = (Citrus)lem;
Grapefruit g = new Grapefruit();|The cast in line 2 is not necessary.The code c
ompiles, and throws an exception at line 3.
Suppose class bbb.Bbb, which extends aaa.AAA, wants to override callMe()|public
,protected
class Zebra extends Animal |Class Zebra generates a compiler error.
What code at line 4 results in a class that compiles?|super();this(1.23f);
What relationship does the extends keyword represent?| is a
When should objects stored in a Set implement the java.util.Comparable interfac
e?|When the Set is a TreeSet
Which methods below honor the hash code contract?|public int hashCode() { r
eturn a; },(int)Math.random();
plainVec; Vector<String> fancyVec;|Attempting to add anything other than a str
ing to fancyVec results in a compiler error.
The declaration of the java.util.Collection interface is interface Collection <
E>|public boolean addAll(Collection<? extends E> c)
package ocean; public class Fish {|public void swim() { },size = 12;
Assuming App.class is stored in an appropriate location in file appjar.jar, wha
t is printed when you type the following command line?|4
public class Wrapper { public int x;|n is 10, w.x is 11
When does the string created on line 2 become eligible for garbage collection?|A
fter line 3
What is -15 % -10?|-5
is a set of java API for executing SQL statements | JDBC
method is used to wait for a client to initiate communications | accept()
drivers that are written partly in the Java programming language and partly in n
ative code. These drivers use a native client library specific to the data sourc
e to which they connect | Type 2
drivers that are pure Java and implement the network protocol for a specific dat
a source. The client connects directly to the data source | Type 4
drivers that use a pure Java client and communicate with a middleware server usi
ng a database-independent protocol. The middleware server then communicates the
client's requests to the data source | Type 3
drivers that implement the JDBC API as a mapping to another data access API, suc
h as ODBC. Drivers of this type are generally dependent on a native library, whi
ch limits their portability | Type 1
System.out.println(a.doit(4, 5)) | Line 26 prints a to System.out
Which two are true if a NullPointerException is thrown on line 3 of class C | co
de on line 29, The exception
What lines are output if the constructor at line 3 throws a MalformedURLExceptio
n | Bad URL, Doing finally, Carrying
What lines are output if the methods at lines 3 and 5 complete successfully with
out throwing any exceptions | Success, Doing, Carrying
If lines 24, 25 and 26 were removed, the code would compile and the output would
be 1 | 3.The code, would be 1, 2
An exception is thrown at runtime | An exception
first second first third snootchy 420 | third second first snootchy 420
dialog prevents user input to other windows in the application unitl the dialog
is closed | Modal
You would like to write code to read back the data from this file. Which solutio
ns will work | 2.FileInputStream, RandomAccessFile
A Java monitor must either extend Thread or implement Runnable | F
A monitor called mon has 10 threads in its waiting pool; all these waiting threa
ds have the same priority. One of the threads is thr1 | You cannot specify
A programmer needs to create a logging method that can accept an arbitrary numbe
r of arguments. For example, it may be called in these ways | public void logIt(
String... msgs)
A signed data type has an equal number of non-zero positive and negative values
available | F
A thread wants to make a second thread ineligible for execution. To do this, the
first thread can call the yield() method on the second thread | F
catch (InterruptedException e) | running some time
object is used to submit a query to a database | Statement
object is uses to obtain a Connection to a Database | DriverManager
After execution of the following code fragment, what are the values of the varia
bles x, a, and b | x13, a7, b8
Yen and Euro both return correct Country value | 2.Euro returns, error at line
25
BigOlLongStringWithMeaninglessName | tick all
Compilation of class A will fail. Compilation of class B will succeed | B fail,
A succeed
Line 46 will compile if enclosed in a try block, where TestException is caught |
2.if the enclosing, is caught
Holder h = new Holder() | 101
Decrementer dec = new Decrementer() | 12.3
Test t = (new Base()).new Test(1) | 2.new Test(1), new Test(1, 2)
Base(int j, int k, int l) | 2.Base(), Base(int j, int k)
Line 12 will not compile, because no version of crunch() takes a char argument |
output: int version
output results when the main method of the class Sub is run | Value 5 This value
6
Float floater = new Float(3.14f) | Line 6
The application must be run with the -enableassertions flag or another assertion
enabling flag | dai nhat, one or more
After line 3 executes, the StringBuffer object is eligible for garbage collectio
n | line 2 executes..collection
The code will compile but will throw an exception at line 7, because runtime con
version from an interface to a class is not permitted | type SwampThing
The code will compile and run, but the cast in line 6 is not required and can be
eliminated | The code will compile and run
for (int i = 0; i < 2; i++) | 4.i0,j12 - i1,j02
outer: for (int i = 0; i < 2; i++) | i = 1 j = 0
The code will compile but will throw an exception at line 7, because runtime con
version from an interface to a class is not permitted | Line 7 will not compile
int[] x = new int[25] | 2.x[24]=0, x.length is 25
public float aMethod(float a, float b) throws Exception | int a,b float p,q
public float aMethod(float a, float b, int c) throws Exception | 3.int a,b. floa
t a,b-int c. private
Given a string constructed by calling s = new String("xyzzy"), which of the call
s modifies the string | None of the above
Given arrays a1 and a2, which call returns true if a1 and a2 have the same lengt
h, and a1[i].equals(a2[i]) for every legal index i | Arrays.equals(a1, a2)
Assuming the class does not perform custom serialization, which fields are writt
en when an instance of Xyz is serialized | 3.Public, Private, Volatile
can legally be placed before aMethod() on line 3 and be placed before aMethod()
on line 8 | 3: private; 8: protected
NUTMEG, CINNAMON, CORIANDER, ROSEMARY | 3.Spice sp, Spice, String
List<String> names = new ArrayList<String>() | 2.Iterator, for
Compilation fails because of an error in line 15 | error in line 19
1 2 3 | 2 3
public interface B inheritsFrom A | B extends A
protected double getSalesAmount() { return 1230.45; } | 2.public, protected
Line 16 creates a directory named d and a file f within it in the file system |
3.An
exception, Line 13, line 14
Nav.Direction d = Nav.Direction.NORTH | Nav.Direction.NORTH
new class Foo { public int bar() { return 1; } } | new Foo()
IllegalArgumentException | StackOverflowError
Circle c = new Circle(); c.Shape.setAnchor(10,10); c.Shape.draw() | Shape s = ne
w Circle...s.draw()
Compilation fails because of an error in line 12 | 1 2 3
NullPointerException | Compilation fails
A NumberFormatException is thrown by the parse method at runtime | Compilation f
ails
An exception is thrown at runtime | Compilation fails
passed An AssertionException is thrown without the word stuff added to the stack t
race | An AssertionError...with the
collie | collie harrier
doStuff x = 6 main x = 6 | doStuff x =5 main x =5
The setCardlnformation method breaks encapsulation | The ownerName
The value of all four objects prints in natural order | Compilation fails...line
29
The code on line 33 executes successfully | 3.33 throws, 35 throws, 33 executes
What is the result if a NullPointerException occurs on line 34 | ac
Compilation will fail because of an error in line 55 | Line 57...value 3
java -ea test file1 file2 | 2.java -ea test, dai nhat
String s = 123456789 ; s = (s- 123 ).replace(1,3, 24 ) - 89 | 2.delete(4,6),
delete(2,5)
rt( 1, 24 )
The Point class cannot be instatiated at line 15 | Line.Point p = new Line.Point
()
for( int i=0; i< x.length; i++ ) System.out.println(x[i]) | 2.for(int z : x),
dai nhat
int MY_VALUE = 10 | 3.final, static, public
Compilation fails because of an error in line: public void process() throws Runt
imeException | A Exception
How can you ensure that multithreaded code does not deadlock | There is no singl
e
How can you force garbage collection of an object | Garbage collection
How do you prevent shared data from being corrupted in a multithreaded environme
nt | Access the variables
How do you use the File class to list the contents of a directory | String[] con
tents
The number of bytes depends on the underlying system | 8
How many locks does an object have | One
If all three top-level elements occur in a source file, they must appear in whic
h order | Package declaration, imports
the two classes are in different packages, and class X has a protected method ca
lled abby(), then any instance of Y may call the abby() method of any | F
TestThread3 ttt = new TestThread3 | Y
If you need a Set implementation that provides value-ordered iteration, which cl
ass should you use | TreeSet
In order for objects in a List to be sorted, those objects must implement which
interface and method | Comparable...compareTo
after execution of line 1, sbuf references an instance of the StringBuffer class
. After execution of line 2, sbuf still references the same instance | T
what are the possible types for variable result | int, long, float, double
helps manage the connection between a Java program and a database | Connection
Is it possible to define a class called Thing so that the following method can r
eturn true under certain circumstances | Y
Is it possible to write code that can execute only if the current thread owns mu
ltiple locks | Y
JDBC supports ______ and ______ models | Two-tier and three-tier
MVC is short call of | Model-View-Controller
No output because of compile error at line: System.out.println("b="+b) | b = b *
b1
Object ob2= new Object() | Have a nice day
Object ob2= ob1 | ob1 equals ob2, ob1==ob2
String s2 = "xyz" | Line 4, Line 6
String s2 = new String("xyz") | Line 6
String s2 = new String(s1) | Line 6
Select correct statement about RMI | All the above
Select correct statement(s) about remote class | All the others choices
Select correct statements about remote interface | All the others choices
Select INCORRECT statement about serialization | When an Object Output
Select INCORRECT statement about deserialize | We use readObject
Select incorrect statement about RMI server | A client accesses
Select incorrect statement about ServerSocket class | To make the new object
Select incorrect statement about Socket class | server through UDP
Select the correct statement about JDBC two-tier processing model | A user's com
mands
SQL keyword ___ is followed by the selection criteria that specify the rows to s
elect in a query | WHERE
Statement objects return SQL query results as | ResultSet
When a JDBC connection is created, it is in auto-commit mode | Both 1 and 2 are
true
Suppose a method called finallyTest() consists of a try block, followed by a cat
ch block, followed by a finally block | If the JVM doesn't crash
Suppose a source file contains a large number of import statements and one class
definition. How do the imports affect the time required to load the class | no
additional time
Suppose a source file contains a large number of import statements. How do the i
mports affect the time required to compile the source file | slightly more time
Suppose class A extends Object; Class B extends A; and class C extends B. Of the
se, only class C implements java.io.Externalizable | C must have a
Suppose class A extends Object; class B extends A; and class C extends B. Of the
se, only class C implements java.io.Serializable | B must have a
Suppose class A has a method called doSomething(), with default access. Suppose
class B extends A and overrides doSomething() | private
Suppose class Supe, in package packagea, has a method called doSomething(). Supp
ose class Subby, in package packageb, overrides doSomething() | 2.public, protec
ted
void doSomething(int a, float b) | public...(int a, float b)
Suppose interface Inty defines five methods. Suppose class Classy declares that
it implements Inty but does not provide implementations for any of the five inte
rface methods | 2.declared abstract, may not be
Suppose prim is an int and wrapped is an Integer. Which of the following are leg
al Java statements | All the above
Suppose salaries is an array containing floats. Which of the following are valid
loop control statements for processing each element of salaries | for (float f:
salaries)
Suppose the declared type of x is a class, and the declared type of y is an inte
rface. When is the assignment x = y; legal | When the...x is Object
Suppose the type of xarr is an array of XXX, and the type of yarr is an array of
YYY. When is the assignment xarr = yarr; legal | Sometimes
Suppose x and y are of type TrafficLightState, which is an enum. What is the bes
t way to test whether x and y refer to the same constant | if (x == y)
Suppose you are writing a class that will provide custom deserialization. What a
ccess mode should the readObject() method have | private
Suppose you are writing a class that will provide custom serialization. What acc
ess mode should the writeObject() method have | private
Suppose you want to create a custom thread class by extending java.lang.Thread i
n order to provide some special functionality | Override run()
Suppose you want to write a class that offers static methods to compute hyperbol
ic trigonometric functions. You decide to subclass java.lang.Math and provide th
e new functionality as a set of static methods | subclass java.lang.Math
Swing components cannot be combined with AWT components | T
class is the primary class that has the driver information | DriverManager
class is used to implement a pull-down menu that provides a number of items to s
elect from | Menu
The element method alters the contents of a Queue | F
The Swing component classes can be found in the | javax.swing
There are two classes in Java to enable communication using datagrams namely | D
ataPacket and DataSocket
Compilation of Parrot.java fails at line 7 because method getRefCount() is stati
c in the superclass, and static methods may not be overridden to be nonstatic |
dai nhat: nonstatic
Compilation of Nightingale will succeed, but an exception will be thrown at line
10, because method fly() is protected in the superclass | The program...After:
2
void doSomething() throws IOException, EOFException | ngan-dai nhat, throws EOFE
xception
URL referring to databases use the form | protocol:subprotocol:datasoursename
What are the legal types for whatsMyType | There are no possible legal types
What does the following code do | Throws an exception
There is no output because the code throws an exception at line 1 | output is i
= 20
1000 | -1
What happens when you try to compile and run the following application | thrown
at line 9
The code compiles, and prints out >>null<< | out >>null<<
An exception is thrown at line 6 | thrown at line 7
What is -50 >> 2 | -13
What is 7 % -4 | 3
What is -8 % 5 | -3
What is the difference between the rules for method-call conversion and the rule
s for assignment conversion | There is no difference
The code will compile as is. No modification is needed | On line 1, remove
What is the range of values that can be assigned to a variable of type byte | ?2
mu7 through 2mu7 ? 1
What is the range of values that can be assigned to a variable of type short | ?
2mu15 through
The code compiles and executes; afterward, the current working directory contain
s a file called datafile | The code fails to compile
What is the return type of the instanceof operator | A boolean
What method of the java.io.File class can create a file on the hard drive | crea
teNewFile()
The output: value is 99.99 | value is 9.0
The output: b contains 250 | b contains 5
What would be the output from this code fragment | message four
When a byte is added to a char, what is the type of the result | int
When a negative byte is cast to a long, what are the possible values of the resu
lt | Negative
When a negative long is cast to a byte, what are the possible values of the resu
lt | All the above
When a short is added to a float, what is the type of the result | float
When comparing java.io.BufferedWriter to java.io.FileWriter, which capability ex
ists as a method in only one of the two | writing a line
When does an exception's stack trace get recorded in the exception object | is c
onstructed
When is it appropriate to pass a cause to an exception's constructor | in respon
se to catching
When is it appropriate to write code that constructs and throws an error | Never
When is x & y an int | Sometimes
When the user attempts to close the frame window, _______ event in generated | w
indow closing
When the user selects a menu item, _______ event is generated | Action event
Java programming language, the compiler converts the human-readable source file
into platform-independent code that a Java Virtual Machine can understand | byte
code
Whenever a method does not want to handle exceptions using the try block, the |
throws
Which are the correct statements used for getting connection object to connect t
o SQL Server database | String url =jdbc:odbc
Which class and static method can you use to convert an array to a List | Arrays
.asList
Which is four-step approach to help you organize your GUI thinking | Identify, I
solate, Sketch
Which is the four steps are used in working with JDBC | Connect, Create, Look
Which JDBC processing model that requires a JDBC driver that can communicate wi
th the particular data source being accessed | two-tier
Which line of code tells a scanner called sc to use a single digit as a delimite
r | sc.useDelimiter("\\d")
Man has the best friend who is a Dog | private Dog bestFriend
Which methods return an enum constant s name | 2.name(), toString()
Which modifier or modifiers should be used to denote a variable that should not
be written out as part of its class's persistent state | transient
Which of the following are legal argument types for a switch statement | 3.byte,
int, char
Which of the following are legal enums | 3.ngan-dai nhat, lion int weight
Which of the following are legal import statements | 2.import...Vector, Vector.*
Which of the following are legal loop constructions | for (int k=0, j+k != 10; j
++,k++)
Which of the following are legal loop definitions | None of the above
double d = 1.2d5 | 2.double d = 1.2d, 1.2D
int d = 0XABCD | 2.int c = 0xabcd, dai nhat
char c = 0x1234 | 2.0x.., '\u1234'
Vector <String> theVec = new Vector<String>() | 2.List...<String>(), dai nhat
Which of the following are methods of the java.util.SortedMap interface | headMa
p, tailMap, subMap
Which of the following are methods of the java.util.SortedSet interface | All th
e above
System.out has a println() method | All the above
The JVM runs until there is only one non-daemon thread | are no non-daemon
When an application begins running, there is one non-daemon thread, whose job is
to execute main() | 3.nhat, thread, non-daemon thread
When you declare a block of code inside a method to be synchronized, you can spe
cify the object on whose lock the block should synchronize | 2.the method always
, nhat
An enum definition should declare that it extends java.lang.Enum | 2.contain pub
lic, private
Primitives are passed by reference | 2.by value
An anonymous inner class that implements several interfaces may extend a parent
class other than Object | implement at most, class may extend
Which of the following are valid arguments to the DataInputStream constructor |
FileInputStream
Which of the following are valid mode strings for the RandomAccessFile construct
or | All the above
Which of the following calls may be made from a non-static synchronized method |
All the above
Which of the following classes implement java.util.List | 2.ArrayList, Stack
Which of the following classes implements a FIFO Queue | LinkedList
Which of the following declarations are illegal | 3.ngan-dai nhat, double d
int x = 6; if (!(x > 3)) | 2.dai nhat, x = ~x
String x = "Hello"; int y = 9; if (x == y) | 2.ngan nhat, x=x+y
Which of the following expressions results in a positive value in x | int x = 1;
x = x >>> 5
Which of the following interfaces does not allow duplicate objects | Set
Which of the following is not appropriate situations for assertions | Preconditi
ons of a public method
Which of the following is NOTa valid comment | /* comment
Which of the following is the most appropriate way to handle invalid arguments i
n a public method | IllegalArgumentException
Readers have methods that can read and return floats and doubles | None of the a
bove
An enum definition may contain the main() method of an application | All the abo
ve
Which of the following may appear on the left-hand side of an instanceof operato
r | A reference
Which of the following may appear on the right-hand side of an instanceof operat
or | 2.A class, An interface
Which of the following may be declared final | 2.Classes, Methods
Which of the following may be statically imported | 2.Static method, Static fiel
d
Which of the following may follow the static keyword | 3.Data, Methods, Code blo
cks
Which of the following may legally appear as the new type (between the parenthes
es) in a cast operation | All of
Which of the following may not be synchronized | Classes
Which of the following may override a method whose signature is void xyz(float f
) | 2.void, public void xyz(float f)
Which of the following methods in the Thread class are deprecated | suspend() an
d resume()
Which of the following operations might throw an ArithmeticException | None of
Which of the following operators can perform promotion on their operands | 3.con
g, tru, xap xi
Which of the following restrictions apply to anonymous inner classes | must be d
efined
Which of the following should always be caught | Checked exceptions
Which of the following signatures are valid for the main() method entry point of
an application | 2.static void...(String arg[])
Which of the following statements about the wait() and notify() methods is true
| calls wait() goes into
Which of the following statements about threads is true | Threads inherit their
A final class may not contain non-final data fields | may not be extended
An abstract class must declare that it implements an interface | None
An abstract class may not have any final methods | Only statement 2
Only object references are converted automatically; to change the type of a prim
itive, you have to do a cast | Both primitives
Transient methods may not be overridden | variables are not
Object references can be converted in both method calls and assignments, but the
rules governing these conversions are very different | conversions are identica
l
Bytecode characters are all 16 bits | Unicode characters
To change the current working directory, call the changeWorkingDirectory() metho
d of the File class | None
When you construct an instance of File, if you do not use the file-naming semant
ics of the local machine, the constructor will throw an IOException | None
When the application is run, thread hp1 will execute to completion, thread hp2 w
ill execute to completion, then thread hp3 will execute to completion | None of
Compilation succeeds, although the import on line 1 is not necessary. During exe
cution, an exception is thrown at line 3 | fails at line 2
Compilation fails at line 1 because the String constructor must be called explic
itly | succeeds. No exception
Line 4 executes and line 6 does not | Line 6 executes
There will be a compiler error, because class Greebo does not correctly implemen
t the Runnable interface | Runnable interface
The acceptable types for the variable j, as the argument to the switch() constru
ct, could be any of byte, short, int, or long | value is three
The returned value varies depending on the argument | returns 0
Lines 5 and 12 will not compile because the method names and return types are mi
ssing | output x = 3
Line 13 will not compile because it is a static reference to a private variable
| output is x = 104
Which statements about JDBC are NOT true | 2.database system, DBMS
Which two code fragments correctly create and initialize a static array of int
elements | 2.a = { 100,200 }, static
Which two of the following interfaces are at the top of the hierarchies in the J
ava Collections Framework | 2.Map, Collection
A new directory called dirname and a new file called filename are created, both
in the current working directory | No directory
protected class Cat extends Owner | public class Cat extends Pet
Date vaccinationDue | 2.boolean, String
What is -15 % -10 | -5
command line on a Windows system | 2.must contain the statement, the file
The string created on line 2 does not become eligible for garbage collection in
this code | After line 3
When the application runs, what are the values of n and w.x after the call to bu
mp() in the main | n is 10, w.x is 11
The addAll() method of that interface takes a single argument, which is a ref
erence to a collection whose elements are compatible with E. What is the declar
ation of the addAll() method | addAll(Collection<? extends E> c)
If you want a vector in which you know you will only store strings, what are the
advantages of using fancyVec rather than plainVec | Attempting to...compiler er
ror
When should objects stored in a Set implement the java.util.Comparable interfac
e | Set is a TreeSet
What relationship does the extends keyword represent | is a
class bbb.Bbb, which extends aaa.AAA, wants to override callMe(). Which access m
odes for callMe() in aaa.AAA will allow this | 2.public, protected
Lemon lem = new Lemon(); Citrus cit = new Citrus() | 3.cit = lem, cit=(Citrus),
lem=(lemon)
it also has a method called chopWoodAndCarryWater(), which just calls the other
two methods | inappropriate cohesion, inappropriate coupling
sharedOb.wait() | 2.aThread.interrupt, sharedOb.notifyAll
line prints double d in a left-justified field that is 20 characters wide, with
15 characters to the right of the decimal point | System.out.format("%-20.15f",
d)
What code at line 3 produces the following output | String delim = \\d+
How do you generate a string representing the value of a float f in a format a
ppropriate for a locale loc | NumberFormat.getInstance(loc)
you want to use a DateFormat to format an instance of Date. What factors influ
ence the string returned by DateFormat s format() method | 2.LONG, or FULL, The lo
cale
you want to create a class that compiles and can be serialized and deserialized
without causing an exception to be thrown. Which statements are true regarding
the class | 2.dai nhat, ngan nhat
you are writing a class that will provide custom deserialization. The class impl
ements java.io.Serializable (not java.io.Externalizable) | private
What interfaces can be implemented in order to create a class that can be serial
ized | 2.dai nhat, ngan nhat
The file contains lines of 8-bit text, and the 8-bit encoding represents the lo
cal character set, as represented by the cur- rent default locale. The lines are
separated by newline characters | FileReader instance
shorty is a short and wrapped is a Short | all
How is IllegalArgumentException used | 2.certain methods, public methods
While testing some code that you are developing, you notice that an ArrayIndexO
utOf- BoundsException is thrown. What is the appropriate reaction | None
Which lines check that x is equal to four? Assume assertions are enabled at com
pile time and runtime | 2.assert x == 4
int[] ages = { 9, 41, 49 }; int sum = 0 | 2.i<ages.length, for (int i:ages)
Which of the following types are legal arguments of a switch statement | enums,
bytes
class A extends java.util.Vector { private A(int x) | does not create a defau
lt
void callMe(String names) | method, names is an array
Given a class with a public variable theTint of type Color, which of the followi
ng methods are consistent with the JavaBeans naming standards | public Color ge
tTheTint()
are valid arguments to the DataInputStream constructor | FileInputStream
are valid mode strings for the RandomAccessFile constructor | r, rw, rws, rwd
method of the java.io.File class can create a file on the hard drive | createNe
wFile()
class A extends Object; Class B extends A; and class C extends B. Of these, only
class C implements java.io.Externalizable | C must have
class A extends Object; class B extends A; and class C extends B. Of these, only
class C implements java.io.Serializable | B must have
you are writing a class that will provide custom deserialization. The class impl
ements java.io.Serializable (not java.io.Externalizable) | private
you are writing a class that will provide custom serialization. The class implem
ents java.io.Serializable (not java.io.Externalizable) | private
How do you use the File class to list the contents of a directory | String[] c
ontents = myFile.list();
call returns true if a1 and a2 have the same length, and a1[i].equals(a2[i]) fo
r every legal index i | java.util.Arrays.equals(a1, a2)
line of code tells a scanner called sc to use a single digit as a delimiter | sc
.useDelimiter( \\d )
you want to write a class that offers static methods to compute hyperbolic trigo
nometric functions. You decide to subclass java.lang.Math and provide the new f
unctionality as a set of static methods | java.lang.Math
Given a string constructed by calling s = new String( xyzzy ), which of the calls
mo
difies the string | none
Suppose you want to create a custom thread class by extending java.lang.Thread
in order to provide some special functionality. Which of the following must you
do | Override run()
you prevent shared data from being corrupted in a multithreaded environment | Ac
cess the variables
Is it possible to write code that can execute only if the current thread owns
multiple locks | yes
Which of the following may not be synchronized | Classes
statements about the wait() and notify() methods is true | pool of waiting th
reads
methods in the Thread class are deprecated | suspend() and resume()
A Java monitor must either extend Thread or implement Runnable | F
One of the threads is thr1. How can you notify thr1 so that it alone moves from
the Waiting state to the Ready state | You cannot specify
A thread wants to make a second thread ineligible for execution. To do this,
the first thread can call the yield() method on the second thread | F
Which methods return an enum constant s name | name(), toString()
restrictions apply to anonymous inner classes | inside a code block
A pet has an owner, a registration date, and a vaccination-due date. A cat is a
pet that has a flag indicating whether it has been neutered, and a textual d
escription of its markings | boolean, string
Which of the following are valid declarations? Assume java.util | 1Vector 2Set 3
Map string,string
You can determine all the keys in a Map in which of the following ways | Set ob
ject from the Map
What keyword is used to prevent an object from being serialized | transient
abstract class can contain methods with declared bodies. | E. public, protecte
d, default, private
access modifier allows you to access method calls in libraries not created in J
ava | native
Which of the following statements are true? (Select all that apply.) | object c
annot reassigned
The keyword extends refers to what type of relationship | is a
keywords is used to invoke a method in the parent class | super
What is the value of x after the following operation is performed | 3
method call is used to tell a thread that it has the opportunity | notify()
Assertions are used to enforce all but which | Exceptions
force garbage collection by calling System.gc(). | B. False
Select the valid primitive data type | 1.boolean 2.char 3.float
How many bits does a float contain | 32
What is the value of x after the following line is executed | 32
StringBuffer is slower than a StringBuilder, but a StringBuffer | True
list of primitives ordered in smallest to largest bit size representation | D.
char, int, float, long
Which class provides locale-sensitive text formatting for date and time informat
ion | java.text.DateFormat
int x = 9; byte b = x | False
Which of the following code snippets compile | 1.Integer 2.Integer 3.byte
Java arrays always start at index 1 | False
accurately describes how variables are passed to methods | that are primitive t
ype are passed by value
change the value that is encapsulated by a wrapper class after you have instan
| None of the above.
The class implements java.io.Serializable (and not java.io.Externalizable) | pri
vate readObject
A signed data type has an equal number of non-zero positive and negative value
s | False
signatures are valid for the main() method entry point of an application | publi
c static void main(String[] args)
three top-level elements occur in a source file, they must appear | Package decl
aration, imports, class/interface/enum definitions
int[] x = new int[25] | x[24] is 0 and x.length is 25
How can you force garbage collection of an object | Garbage collection cannot
be forced.
range of values that can be assigned to a variable of type short | -215 through
215 - 1
range of values that can be assigned to a variable of type byte | -27 through 2
7 - 1
How do the imports affect the time required to compile the source file | Compi
lation takes slightly more time
How do the imports affect the time required to load the class? | Class loading
takes no additional time
legal import statements | 1.import java.util.Vector 2.import static java.ut
il.Vector
may be statically imported | 1.Static method names 2.Static field names
int c = 0xabcd and int d = 0XABCD | 2 dap an
double d = 1.2d and double d = 1.2D | 2 dap an
char c = \u1234 | 1 dap an
passed by value and passed by value | 2 dap an
int x = 6; if (!(x > 3)) and int x = 6; x = ~x | 2 dap an
int x = 1; x = x >>> 5 | 1 dap an
int y = 9; x += y; and int y = 9; x = x + y; | 2 dap an
What is -8 % 5 | -3
What is 7 % -4? | 3
ob1 == ob2 | No
When a byte is added to a char | int
When a short is added to a float | float
ArithmeticException | 1.None of these 2./
What is the return type of the instanceof operator | boolean
may appear on the left-hand side of an instanceof operator | reference
may appear on the right-hand side of an instanceof operator | class and interfa
ce
What is -50 >> 1 | -25
default String s ,, abstract double d ,, double hyperbolic | 3 dap an
A final class may not have any abstract methods | true
denote a variable that should not be written out as part of its class s persistent
state | transient
Both primitives and object references can be both converted and cast | dap an
and the rules governing these conversions are identical | dap an
may legally appear as the new type (between the parentheses) in a cast operati
on | All of the above
type of x is a class, and the declared type of y is an interface. When is the as
signment x = y | When the type of x is Object
xarr is an array of XXX, and the type of yarr is an array of YYY | Sometimes
When is x & y an int | Sometimes
negative long is cast to a byte | All of the above
negative byte is cast to a long | Negative
operators can perform promotion on their operands | + - ~(nga)
difference between the rules for method-call conversion and the rules for assign
ment conversion | There is no difference
Which of the following are appropriate situations for assertions | DAP AN SAI :
Preconditions of a public method
appropriate way to handle invalid arguments in a public method | IllegalArgumen
tException
Suppose salaries is an array containing floats | for (float f:salaries)
Suppose a method called finallyTest() consists of a try block | If the JVM does
n t crash and
appropriate to pass a cause to an exception s constructor | thrown in response to
catching of a different exception type
Which of the following should always be caught | Checked exceptions
When does an exception s stack trace get recorded in the exception object | is c
onstructed
Which of the following are valid declarations? Assume java.util.* is imported. |
Map<String> m;
You can determine all the keys in a Map in which of the following ways?|By getti
ng a Set object from the Map and iterating through it.
What keyword is used to prevent an object from being serialized?|transient
An abstract class can contain methods with declared bodies.|True
Select the order of access modifiers from least restrictive to most restrictive.
|public, protected, default, private
Which access modifier allows you to access method calls in libraries not created
in Java?|native
Which of the following statements are true? (Select all that apply.)|A final obj
ect cannot be reassigned a new address in memory.
The keyword extends refers to what type of relationship?| is a
Which of the following keywords is used to invoke a method in the parent class?|
super
What is the value of x after the following operation is performed? x = 23 %
4; |3
What method call is used to tell a thread that it has the opportunity to run?|n
otify()
Assertions are used to enforce all but which of the following?|Exceptions
The developer can force garbage collection by calling System.gc().|False
Select the valid primitive data types. (Select all that apply.)|boolean, char, f
loat
How many bits does a float contain?|32
What is the value of x after the following line is executed? x = 32 * (31 -
10 * 3); |32
A StringBuffer is slower than a StringBuilder, but a StringBuffer is threadsafe.
|True
Select the list of primitives ordered in smallest to largest bit size representa
tion.|char, int, float, long
Which class provides locale-sensitive text formatting for date and time informat
ion?|java.text.DateFormat
The following line of code is valid. int x = 9; byte b = x;|False
Which of the following code snippets compile?|Integer i = 7;, Integer i =
new Integer(5); int j = i;, byte b = 7;
Java arrays always start at index 1.|False
Which of the following statements accurately describes how variables are passed
to methods?|Arguments that are primitive type are passed by value.
How do you change the value that is encapsulated by a wrapper class after you h
ave instan- tiated it?|None of the above.
Suppose you are writing a class that provides custom deserialization. The class
implements java.io.Serializable (and not java.io.Externalizable). What method s
hould imple- ment the custom deserialization, and what is its access mode?|priva
te readObject
A signed data type has an equal number of non-zero positive and negative values
available.|False
Choose the valid identifiers from those listed here. (Choose all that apply.)|Bi
gOlLongStringWithMeaninglessName, $int, bytes, $1, finalist
Which of the following signatures are valid for the main() method entry point of
an application? (Choose all that apply.)|public static void main(String arg[])
, public static void main(String[] args)
If all three top-level elements occur in a source file, they must appear in whi
ch order?|Package declaration, imports, class/interface/enum definitions.
How can you force garbage collection of an object?|Garbage collection cannot b
e forced.
What is the range of values that can be assigned to a variable of type short?| ?
2^15 through 2^15 ? 1
What is the range of values that can be assigned to a variable of type byte?| ?2
^7 through 2^7 ? 1
Suppose a source file contains a large number of import statements. How do the i
mports affect the time required to compile the source file?| Compilation takes
slightly more time.
Suppose a source file contains a large number of import statements and one class
definition.How do the imports affect the time required to load the class?|Cla
ss loading takes no additional time.
Which of the following are legal import statements?| import java.util.Vector;,
import static java.util.Vector.*;
Which of the following may be statically imported? (Choose all that apply.)| St
atic method names, Static field names
Which of the following are legal? (Choose all that apply.)| int c = 0xabcd;,
int d = 0XABCD;
Which of the following are legal? (Choose all that apply.)| double d = 1.2d;,
double d = 1.2D;
Which of the following are legal?| char c = \u1234 ;
Which of the following are true? (Choose all that apply.)| Primitives are passe
d by value., References are passed by value.
Which of the following expressions are legal? (Choose all that apply.)| int x
= 6; if (!(x > 3)) {}, int x = 6; x = ~x;
Which of the following expressions results in a positive value in x?| int x = 1
; x = x >>> 5;
Which of the following expressions are legal? (Choose all that apply.)| String
x = "Hello"; int y = 9; x += y;, String x = "Hello"; int y = 9; x
= x + y;
What is -8 % 5?|-3
What is 7 % -4?|3
Is it possible to define a class called Thing so that the following method can
return true under certain circumstances? boolean weird(Thing s) { Integer x
= new Integer(5); return s.equals(x); }|Yes
Suppose ob1 and ob2 are references to instances of java.lang.Object. If (ob1 ==
ob2) is false, can ob1.equals(ob2) ever be true?|No
When a byte is added to a char, what is the type of the result?|int
When a short is added to a float, what is the type of the result?|float
Which statement is true about the following method?int selfXor(int i) { return
i ^ i;}|It always returns 0
Which of the following operations might throw an ArithmeticException?|None of th
ese
Which of the following operations might throw an ArithmeticException?|/
Which of the following may appear on the left-hand side of an instanceof operat
or?|A reference
Which of the following may appear on the right-hand side of an instanceof operat
or? (Choose all that apply.)|A class, An interface
What is -50 >> 1?|-25
Which of the following declarations are illegal? (Choose all that apply.)| defau
lt String s;, abstract double d;, abstract final double hyperboli
cCosine();
Which of the following statements is true?|A final class may not have any abstra
ct methods.
Which of the following statements is true?|Transient variables are not serialize
d.
Which modifier or modifiers should be used to denote a variable that should not
be written out as part of its class s persistent state? (Choose the shortest pos
sible answer.)|transient
Suppose class Supe, in package packagea, has a method called doSomething(). Supp
ose class Subby, in package packageb, overrides doSomething(). What access mod
es may Subby s version of the method have? (Choose all that apply.)|public,
p
rotected
Which of the following statements are true?|None of the above.
Suppose interface Inty defines five methods. Suppose class Classy declares that
it implements Inty but does not provide implementations for any of the five int
erface methods. Which is/are true?|The class will compile if it is declared abst
ract., The class may not be instantiated.
Which of the following may be declared final? (Choose all that apply.)|Classes,
Data, Methods
Which of the following may follow the static keyword? (Choose all that apply.)|
Data, Methods, Code blocks enclosed in curly brackets
Suppose class A has a method called doSomething(), with default access. Suppose
class B extends A and overrides doSomething(). Which access modes may apply to
B s version of doSomething()? (Choose all that apply.)|public, protected, Def
ault
True or false: If class Y extends class X, the two classes are in different pack
ages, and class X has a protected method called abby(), then any instance of Y
may call the abby() method of any other instance of Y.|False
Which of the following statements are true?|A final class may not be extended.
Which of the following statements is correct? (Choose one.)|Both primitives and
object references can be both converted and cast.
Which of the following statements is true? (Choose one.)|Object references can b
e converted in both method calls and assignments, and the rules governing the
se conversions are identical.
Which of the following statements is true? (Choose one.)|Line 7 will not compile
; an explicit cast is required to convert a Washer to a SwampThing.
Which of the following may legally appear as the new type (between the parenthe
ses) in a cast operation?|All of the above
Suppose the declared type of x is a class, and the declared type of y is an inte
rface. When is the assignment x = y; legal?|When the type of x is Object
Suppose the type of xarr is an array of XXX, and the type of yarr is an array of
YYY. When is the assignment xarr = yarr; legal?|Sometimes
When is x & y an int? (Choose one).|Sometimes
What are the legal types for whatsMyType? short s = 10; whatsMyType = !s;|There
are no possible legal types.
When a negative long is cast to a byte, what are the possible values of the resu
lt?|All of the above
Which of the following operators can perform promotion on their operands? (Choo
se all that apply.)|+, -, ~
When a negative byte is cast to a long, what are the possible values of the resu
lt?|Negative
What is the difference between the rules for method-call conversion and the rule
s for assignment conversion?|There is no difference; the rules are the same.
Which of the following are appropriate situations for assertions?|Postconditions
of a public method, Preconditions of a private method, Postconditions o
f a private method
Which of the following is the most appropriate way to handle invalid arguments
in a public method?|Throw java.lang.IllegalArgumentException.
Which of the following are legal? (Choose all that apply.)|for (int i=0, j=1; i
<10; i++, j++), for (int i=0, j=1;; i++, j++), for (String s = ;
s.le
ngth()<10; s += ! )
Suppose a method called finallyTest() consists of a try block, followed by a ca
tch block, followed by a finally block. Assuming the JVM doesn t crash and the cod
e does not execute a System.exit() call, under what circumstances will the fina
lly block not begin to execute?|If the JVM doesn t crash and the code does not exe
cute a System.exit() call, the finally block will always execute.
Which of the following are legal loop definitions? (Choose all that apply.)|Non
e of them are legal.
Which of the following are legal argument types for a switch statement?|byte,
int, char
When is it appropriate to pass a cause to an exception s constructor?|When the exc
eption is being thrown in response to catching of a different exception type
Which of the following should always be caught?|Checked exceptions
When does an exception s stack trace get recorded in the exception object?|When
the exception is constructed
When is it appropriate to write code that constructs and throws an error?|Never
Which of the following statements are true? (Choose all that apply.)|Given that
Inner is a nonstatic class declared inside a public class Outer and that appro-
priate constructor forms are defined, an instance of Inner can be constructed l
ike this: new Outer().new Inner()
Which of the following may override a method whose signature is void xyz(float
f)?|void xyz(float f), public void xyz(float f)
Which of the following are true? (Choose all that apply.)|An enum may contain p
ublic method definitions., An enum may contain private data
Which of the following are true? (Choose all that apply.)|An enum definition ma
y contain the main() method of an application., You can call an enum s
toString() method., You can call an enum s wait() method., You can ca
ll an enum s notify() method.
Suppose x and y are of type TrafficLightState, which is an enum. What is the bes
t way to test whether x and y refer to the same constant?|if (x == y)
Which of the following restrictions apply to anonymous inner classes?|They must
be defined inside a code block.
Which of the following are true?|An anonymous inner class may implement at most
one interface., An anonymous inner class may extend a parent class other
than Object.
Which methods return an enum constant s name?|name(), toString()
Suppose class X contains the following method: void doSomething(int a, float b)
{ } Which of the following methods may appear in class Y, which extend
s X?|public void doSomething(int a, float b) { }
A thread wants to make a second thread ineligible for execution. To do this,
the first thread can call the yield() method on the second thread.|False
A monitor called mon has 10 threads in its waiting pool; all these waiting threa
ds have the same priority. One of the threads is thr1. How can you notify thr1
so that it alone moves from the Waiting state to the Ready state?|You cannot s
pecify which thread will get notified.
A Java monitor must either extend Thread or implement Runnable.|False
Which of the following methods in the Thread class are deprecated?|suspend() an
d resume()
Which of the following statements about threads is true?|Threads inherit the
ir priority from their parent thread.
Which of the following statements about the wait() and notify() methods is tr
ue?|The thread that calls wait() goes into the monitor s pool of waiting threads
.
Which of the following may not be synchronized?|Classes
How many locks does an object have?|One
Is it possible to write code that can execute only if the current thread owns
multiple locks?|Yes.
Which of the following are true?|The JVM runs until there are no non-daemon thre
ads.
How do you prevent shared data from being corrupted in a multithreaded environme
nt?|Access the variables only via synchronized methods.
How can you ensure that multithreaded code does not deadlock?|A, B, and C do not
ensure that multithreaded code does not deadlock.
Which of the following are true? (Choose all that apply.)|When you declare a met
hod to be synchronized, the method always synchronizes on the lock of the curren
t object., When you declare a block of code inside a method to be synchron
ized, you can specify the object on whose lock the block should synchronize.
Suppose you want to create a custom thread class by extending java.lang.Thread
in order to provide some special functionality. Which of the following must you
do?|Override run().
Given a string constructed by calling s = new String( xyzzy ), which of the calls
mo
difies the string?|None of the above
Suppose you want to write a class that offers static methods to compute hyperbol
ic trigonometric functions. You decide to subclass java.lang.Math and provide t
he new functionality as a set of static methods. Which one statement is true ab
out this strategy?|The strategy fails because you cannot subclass java.lang.Ma
th.
Suppose prim is an int and wrapped is an Integer. Which of the following are le
gal Java statements? (Choose all that apply.)|prim = wrapped;, wrapped =
prim;, prim = new Integer(9);, wrapped = 9;
Which of the following are legal? (Choose all that apply.)|List<String> theList
= new Vector<String>();, Vector <String> theVec = new Vector<String>()
;
Given the following, Map<String> names = new HashMap<String>(); which of the
following are legal? (Choose all that apply.)|Iterator<String> iter = names.ite
rator();, for (String s:names)
Which of the following classes implement java.util.List?|java.util.ArrayList,
java.util.Stack
Which of the following are methods of the java.util.SortedSet interface?|first,
last, headSet, tailSet, subSet
Which of the following are methods of the java.util.SortedMap interface?|headMap
, tailMap, subMap
Which line of code tells a scanner called sc to use a single digit as a delimite
r?|sc.useDelimiter( \\d );
Given arrays a1 and a2, which call returns true if a1 and a2 have the same leng
th, and a1[i].equals(a2[i]) for every legal index i?|java.util.Arrays.equals(a1
, a2);
Which of the following statements are true?|StringBuilder is generally faster th
an StringBuffer., StringBuffer is threadsafe; StringBuilder is not.
Which of the statements below are true? (Choose all that apply.)|Unicode charact
ers are all 16 bits.
How do you use the File class to list the contents of a directory?|String[] con
tents = myFile.list();
Suppose you are writing a class that will provide custom serialization. The clas
s implements java.io.Serializable (not java.io.Externalizable). What access mode
should the writeObject() method have?|private
Suppose you are writing a class that will provide custom deserialization. The cl
ass implements java.io.Serializable (not java.io.Externalizable). What access m
ode should the readObject() method have?|private
Suppose class A extends Object; class B extends A; and class C extends B. Of the
se, only class C implements java.io.Serializable. Which of the following must be
true in order to avoid an exception during deserialization of an instance of C
?|B must have a no-args constructor.
Suppose class A extends Object; Class B extends A; and class C extends B. Of the
se, only class C implements java.io.Externalizable. Which of the following must
be true in order to avoid an exception during deserialization of an instance of
C?|C must have a no-args constructor.
What method of the java.io.File class can create a file on the hard drive?|crea
teNewFile()
Which of the following are true? (Choose all that apply.)|System.out has a print
ln() method., System.out has a format() method., System.err has a
printl
n() method., System.err has a format () method.
Which of the following are valid mode strings for the RandomAccessFile construct
or? (Choose all that apply.)| r , rw , rws , rwd
Which of the following are valid arguments to the DataInputStream constructor?|F
ileInputStream
Given a class with a public variable theTint of type Color, which of the followi
ng methods are consistent with the JavaBeans naming standards?|public Color get
TheTint()
Which of the following statements are true regarding the following method? void
callMe(String names) { }|Within the method, names is an array containing St
rings.
Which of the following types are legal arguments of a switch statement?|enums,
bytes
Which lines check that x is equal to four? Assume assertions are enabled at com
pile time and runtime.|assert x == 4;, assert x == 4 : x is not 4 ;
Which are appropriate uses of assertions?|Checking preconditions in a private me
thod, Checking postconditions in a private method, Checking postcondition
s in a public method
While testing some code that you are developing, you notice that an ArrayIndexO
utOf- BoundsException is thrown. What is the appropriate reaction?|None of the a
bove.
How is IllegalArgumentException used? (Choose all correct options.)|It is thrown
by certain methods of certain core Java classes to indicate that preconditions
have been violated., It should be used by programmers to indicate that p
reconditions of public methods have been violated.
Suppose shorty is a short and wrapped is a Short. Which of the following are leg
al Java state- ments? (Choose all correct options.)|shorty = wrapped;, wra
pped = shorty;, shorty = new Short((short)9);, shorty = 9;
Which of the following statements are true? (Choose all correct options.)|Strin
gBuilder encapsulates a mutable string., StringBuffer is threadsafe.
Suppose you want to read a file that was not created by a Java program. The file
contains lines of 8-bit text, and the 8-bit encoding represents the local char
acter set, as represented by the cur- rent default locale. The lines are separat
ed by newline characters. Which strategy reads the file and produces Java strin
gs?|Create a FileReader instance. Pass it into the constructor of LineNumberRea
der. Use LineNumberReader s readLine() method.
What interfaces can be implemented in order to create a class that can be serial
ized? (Choose all that apply.)|Have the class declare that it implements java.io
.Serializable. There are no methods in the interface., Have the class decl
are that it implements java.io.Externalizable, which defines two methods: read
External and writeExternal
Suppose you are writing a class that will provide custom deserialization. The cl
ass implements java.io.Serializable (not java.io.Externalizable). What access m
ode should the readObject() method have?|private
Suppose you want to create a class that compiles and can be serialized and deser
ialized without causing an exception to be thrown. Which statements are true r
egarding the class? (Choose all correct options.)|If the class implements java
.io.Externalizable, it must have a no-args constructor., If the class impleme
nts java.io.Serializable and does not implement java.io.Externalizable, its nea
rest superclass that doesn t implement Serializable must have a no-args construct
or.
Suppose you want to use a DateFormat to format an instance of Date. What facto
rs influence the string returned by DateFormat s format() method?|The style, which
is one of SHORT, MEDIUM, LONG, or FULL, The locale
How do you generate a string representing the value of a float f in a format a
ppropriate for a locale loc?|NumberFormat nf = NumberFormat.getInstance(loc);
String s = nf.format(f);
Which line prints double d in a left-justified field that is 20 characters wide,
with 15 characters to the right of the decimal point?|System.out.format("%-20.1
5f", d);
Suppose MyThread extends java.lang.Thread, and MyRunnable implements java.lang.
Runnable (but does not extend Thread). Both classes have no-args constructors. W
hich of the following cause a thread in the JVM to begin execution? (Choose al
l correct options.)|(new MyThread()).start();, (new Thread(new MyRunnable
()))
What code can bThread execute in order to get aThread out of the waiting state,
no matter what other conditions prevail?|aThread.interrupt();, sharedOb.noti
fyAll();
Suppose class Home has methods chopWood() and carryWater(); it also has a method
called chopWoodAndCarryWater(), which just calls the other two methods. Which
statements are true? (Choose all that apply.)|chopWoodAndCarryWater() is an ex
ample of inappropriate cohesion., chopWoodAndCarryWater() is an example of in
appropriate coupling.
Suppose class aaa.Aaa has a method called callMe(). Suppose class bbb.Bbb, which
extends aaa.AAA, wants to override callMe(). Which access modes for callMe() i
n aaa.AAA will allow this?|public, protected
What relationship does the extends keyword represent?| is a
When should objects stored in a Set implement the java.util.Comparable interfac
e?|When the Set is a TreeSet
The java.util.Arrays class has a binarySearch(int[] arr, int key) method. Whi
ch statements are true regarding this method? (Choose all that apply.)|The me
thod is static., The return value is the index in the array of key., Th
e elements of the array must be sorted when the method is called.
When the application runs, what are the values of n and w.x after the call to bu
mp() in the main() method?|n is 10, w.x is 11
What is -15 % -10?|-5
is a set of java API for executing SQL statements.|JDBC
method is used to wait for a client to initiate communications.|accept()
drivers that are written partly in the Java programming language and partly in n
ative code. These drivers use a native client library specific to the data sourc
e to which they connect. Again, because of the native code, their portability is
limited.|Type 2
drivers that are pure Java and implement the network protocol for a specific dat
a source. The client connects directly to the data source.|Type 4
drivers that use a pure Java client and communicate with a middleware server usi
ng a database-independent protocol. The middleware server then communicates the
client's requests to the data source.|Type 3
drivers that implement the JDBC API as a mapping to another data access API, suc
h as ODBC. Drivers of this type are generallydependent on a native library, whic
h limits their portability.|Type 1
A dialog prevents user input to other windows in the application unitl the dialo
g is closed.|Modal
A Java monitor must either extend Thread or implement Runnable.|False
A monitor called mon has 10 threads in its waiting pool; all these waiting threa
ds have the same priority. One of the threads is thr1. How can you notify thr1 s
o that it alone moves from the Waiting state to the Ready state? (Choose one.)|Y
ou cannot specify which thread will get notified.
A signed data type has an equal number of non-zero positive and negative values
available.|False
A thread wants to make a second thread ineligible for execution. To do this, the
first thread can call the yield() method on the second thread.|False
A(n) object is used to submit a query to a database|Statement
A(n) object is uses to obtain a Connection to a Database|DriverManager
After execution of the following code fragment, what are the values of the varia
bles x, a, and b? 1. int x, a = 6, b = 7; 2. x = a++ + b++;|x = 13, a = 7, b
= 8
Choose the valid identifiers from those listed here. (Choose all that apply.)|Bi
gOlLongStringWithMeaninglessName, $int, bytes, $1, finalist
How can you ensure that multithreaded code does not deadlock? (Choose one.)|Ther
e is no single technique that can guarantee non-deadlocking code.
How can you force garbage collection of an object? (Choose one.)|Garbage collect
ion cannot be forced.
How do you prevent shared data from being corrupted in a multithreaded environme
nt? (Choose one.)|Access the variables only via synchronized methods.
How do you use the File class to list the contents of a directory? (Choose one.)
|String[] contents = myFile.list();
How many locks does an object have? (Choose one.)|One
If all three top-level elements occur in a source file, they must appear in whic
h order? (Choose one.)|Package declaration, imports, class/interface/enum defini
tions.
If class Y extends class X, the two classes are in different packages, and class
X has a protected method called abby(), then any instance of Y may call the abb
y() method of any other instance of Y.|False
If you need a Set implementation that provides value-ordered iteration, which cl
ass should you use? (Choose one.)|TreeSet
In order for objects in a List to be sorted, those objects must implement which
interface and method? (Choose one.)|Comparable interface and its compareTo meth
od.
Interface helps manage the connection between a Java program and a databa
se.|Connection
Is it possible to write code that can execute only if the current thread owns mu
ltiple locks?|Yes
JDBC supports and models.|Two-tier and three-tier
MVC is short call of|Model-View-Controller
Select correct statement about RMI. (choose 1)|All the above
Select correct statement(s) about remote class.(choose one)|All the others choic
es
Select correct statements about remote interface. (choose 1)|All the others choi
ces
Select INCORRECT statement about serialization. (choose 1)|When an Object Output
Stream serializes an object that contains references to another object, every r
eferenced object is not serialized along with the original object.
Select INCORRECT statement about deserialize. (choose 1)|We use readObject() met
hod of ObjectOutputStream class to deserialize.
Select incorrect statement about RMI server.(choose 1)|A client accesses a remot
e object by specifying only the server name.
Select incorrect statement about ServerSocket class. (choose 1)|To make the new
object available for client connections, call its accept() method, which returns
an instance of ServerSocket
Select incorrect statement about Socket class. (choose 1)|The java.net.Socket cl
ass contains code that knows how to find and communicate with a server through U
DP.
SQL keyword is followed by the selection criteria that specify the rows to
select in a query|WHERE
Statement objects return SQL query results as objects|ResultSet
Study the statements: 1)When a JDBC connection is created, it is in auto-commit
mode 2)Once auto-commit mode is disabled, no SQL statements will be committe
d until you call the method commit explicitly|Both 1 and 2 are true
Suppose a method called finallyTest() consists of a try block, followed by a cat
ch block, followed by a finally block. Assuming the JVM doesn t crash and the code
does not execute a System.exit() call, under what circumstances will the finall
y block not begin to execute? (Choose one.)|If the JVM doesn't crash and the cod
e does not execute a System.exit() call, the finally block will always execute.
Suppose a source file contains a large number of import statements and one class
definition. How do the imports affect the time required to load the class? (Cho
ose one.)|Class loading takes no additional time.
Suppose a source file contains a large number of import statements. How do the i
mports affect the time required to compile the source file? (Choose one.)|Compil
ation takes slightly more time.
Suppose class A extends Object; Class B extends A; and class C extends B. Of the
se, only class C implements java.io.Externalizable. Which of the following must
be true in order to avoid an exception during deserialization of an instance of
C? (Choose one.)|C must have a no-args constructor.
Suppose class A extends Object; class B extends A; and class C extends B. Of the
se, only class C implements java.io.Serializable. Which of the following must be
true in order to avoid an exception during deserialization of an instance of C?
(Choose one.)|B must have a no-args constructor.
Suppose class A has a method called doSomething(), with default access. Suppose
class B extends A and overrides doSomething(). Which access modes may not apply
to B s version of doSomething()? (Choose one)|private
Suppose class Supe, in package packagea, has a method called doSomething(). Supp
ose class Subby, in package packageb, overrides doSomething(). What access modes
may Subby s version of the method have? (Choose two.)|public, protected
Suppose class X contains the following method:void doSomething(int a, float b) {
} Which of the following methods may appear in class Y, which extends X? (Choo
se one.)|public void doSomething(int a, float b) { }
Suppose interface Inty defines five methods. Suppose class Classy declares that
it implements Inty but does not provide implementations for any of the five inte
rface methods. Which are true? (Choose two.)|The class will compile if it is dec
lared abstract., The class may not be instantiated.
Suppose prim is an int and wrapped is an Integer. Which of the following are leg
al Java statements? (Choose one.)|All the above
Suppose salaries is an array containing floats. Which of the following are valid
loop control statements for processing each element of salaries? (Choose one.)|
for (float f:salaries)
Suppose the declared type of x is a class, and the declared type of y is an inte
rface. When is the assignment x = y; legal? (Choose one.)|When the type of x is
Object
Suppose the type of xarr is an array of XXX, and the type of yarr is an array of
YYY. When is the assignment xarr = yarr; legal? (Choose one.)|Sometimes
Suppose x and y are of type TrafficLightState, which is an enum. What is the bes
t way to test whether x and y refer to the same constant? (Choose one.)|if (x ==
y)
Suppose you are writing a class that will provide custom deserialization. The cl
ass implements java.io.Serializable (not java.io.Externalizable). What access mo
de should the readObject() method have? (Choose one.)|private
Suppose you want to create a custom thread class by extending java.lang.Thread i
n order to provide some special functionality. Which of the following must you d
o? (Choose one.)|Override run().
Suppose you want to write a class that offers static methods to compute hyperbol
ic trigonometric functions. You decide to subclass java.lang.Math and provide th
e new functionality as a set of static methods. Which one statement is true abou
t this strategy?|The strategy fails because you cannot add static methods to a s
ubclass.
Swing components cannot be combined with AWT components.|True
The class is the primary class that has the driver information.|DriverManag
er
The class is used to implement a pull-down menu that provides a number of i
tems to select from.|Menu
The element method alters the contents of a Queue.|False
The Swing component classes can be found in the package.|javax.swing
There are two classes in Java to enable communication using datagrams namely.|Da
taPacket and DataSocket
What are the legal types for whatsMyType? (Choose one.) short s = 10; whatsMyTyp
e = !s;|There are no possible legal types.
What does the following code do? Integer i = null; if (i != null & i.intValue
() == 5) System.out.println("Value is 5");|Throws an exception.
What is -50 >> 2|-13
What is the difference between the rules for method-call conversion and the rule
s for assignment conversion? (Choose one.)|There is no difference; the rules are
the same.
What method of the java.io.File class can create a file on the hard drive?(Choos
e one.)|createNewFile()
When a byte is added to a char, what is the type of the result?|int
When a negative byte is cast to a long, what are the possible values of the resu
lt? (Choose one.)|Negative
When a negative long is cast to a byte, what are the possible values of the resu
lt? (Choose one.)|All the above
When a short is added to a float, what is the type of the result?|float
When comparing java.io.BufferedWriter to java.io.FileWriter, which capability ex
ists as a method in only one of the two? (Choose one.)|writing a line separator
to the stream
When does an exception's stack trace get recorded in the exception object? (Choo
se one.)|When the exception is constructed
When is it appropriate to pass a cause to an exception's constructor? (Choose on
e.)|When the exception is being thrown in response to catching of a different ex
ception type
When is it appropriate to write code that constructs and throws an error?(Choose
one.)|Never
When is x & y an int? (Choose one).|Sometimes
When the user attempts to close the frame window, event in generated.|win
dow closing
When the user selects a menu item, event is generated.|Action event
When you compile a program written in the Java programming language, the compile
r converts the human-readable source file into platform- independent code that a
Java Virtual Machine can understand. What is this platform-independent code cal
led?|bytecode
Whenever a method does not want to handle exceptions using the try block, the
is used.|throws
Which are the correct statements used for getting connection object to connect t
o SQL Server database?|String url ="jdbc:odbc:data_source_name"; Connection con
= DriverManager.getConnection (url, user", "password");
Which class and static method can you use to convert an array to a List?(Choose
one.)|Arrays.asList
Which is four-step approach to help you organize your GUI thinking.(Choose one.)
|Identify needed components. Isolate regions of behavior. Sketch the GUI. Choose
layout managers.
Which is the four steps are used in working with JDBC?| 1)Connect to the databa
se 2)Create a statement and execute the query 3)Look at the result set 4)Close
connection
Which JDBC processing model that requires a JDBC driver that can communicate wi
th the particular data source being accessed?|two-tier
Which line of code tells a scanner called sc to use a single digit as a delimite
r? (Choose one.)|sc.useDelimiter("\\d");
Which Man class properly represents the relationship "Man has the best friend wh
o is a Dog"? (Choose one.)|class Man { private Dog bestFriend; }
Which methods return an enum constant s name? (Choose two.)|name(),
toString(
)
Which modifier or modifiers should be used to denote a variable that should not
be written out as part of its class's persistent state? (Choose the shortest pos
sible answer.)|transient
Which of the following are legal argument types for a switch statement?(Choose t
hree.)|byte, int, char
Which of the following are legal import statements? (Choose two.)||import java.u
til.Vector;, import static java.util.Vector.*;
Which of the following are legal loop constructions? (Choose one.)|int j = 0;
for (int k=0, j+k != 10; j++,k++) { System.out.println("j=" + j + ", k=" + k);
}
Which of the following are legal? (Choose three.)|for (int i=0, j=1; i<10; i++,
j++), for (int i=0, j=1;; i++, j++), for (String s = ""; s.length()<1
0; s += '!')
Which of the following are legal? (Choose two.)|double d = 1.2d;, doub
le d = 1.2D;
Which of the following are legal? (Choose two.)|int c = 0xabcd; int d = 0XABC
D;
Which of the following are legal? (Choose two.)|char c = 0x1234;, cha
r c = '\u1234';
Which of the following are legal? (Choose two.)|List<String> theList = new Vecto
r<String>();, Vector <String> theVec = new Vector<String>();
Which of the following are methods of the java.util.SortedSet interface?(Choose
one.)|All the above
Which of the following are true? (Choose one.)|The JVM runs until there are no n
on-daemon threads.
Which of the following are true? (Choose three.)|When an application begins runn
ing, there is one non-daemon thread,whose job is to execute main()., A thre
ad created by a daemon thread is initially also a daemon thread., A threa
d created by a non-daemon thread is initially also a non-daemon thread.
Which of the following are true? (Choose two.)|When you declare a method to be s
ynchronized, the method always synchronizes on the lock of the current object.,
When you declare a block of code inside a method to be synchronized, you
can specify the object on whose lock the block should synchronize.
Which of the following are true? (Choose two.)|An enum may contain public method
definitions., An enum may contain private data.
Which of the following are true? (Choose two.)|Primitives are passed by value.,
References are passed by value.
Which of the following are true? (Choose two.)|An anonymous inner class may impl
ement at most one interface., An anonymous inner class may extend a parent
class other than Object.
Which of the following calls may be made from a non-static synchronized method?
(Choose one.)|All the above
Which of the following classes implement java.util.List? (Choose two.)|java.util
.ArrayList, java.util.Stack
Which of the following classes implements a FIFO Queue? (Choose one.)|LinkedLis
t
Which of the following declarations are illegal? (Choose three.)|default String
s;, abstract double d;, abstract final double hyperboli
cCosine();
Which of the following expressions are legal? (Choose two.)|int x = 6; if (!(x >
3)) {}, int x = 6; x = ~x;
Which of the following expressions are legal? (Choose two.)|String x = "Hello";
int y = 9; x += y;, String x = "Hello"; int y = 9; x = x + y;
Which of the following expressions results in a positive value in x?(Choose one.
)|int x = 1; x = x >>> 5;
Which of the following interfaces does not allow duplicate objects?(Choose one.)
|Set
Which of the following is not appropriate situations for assertions?(Choose one)
|Preconditions of a public method
Which of the following is NOTa valid comment:|/* comment
Which of the following is the most appropriate way to handle invalid arguments i
n a public method?|Throw java.lang.IllegalArgumentException.
Which of the following may appear on the left-hand side of an instanceof operato
r?|A reference
Which of the following may appear on the right-hand side of an instanceof operat
or? (Choose two.)|A class, An interface
Which of the following may be declared final? (Choose two.)|Classes, Meth
ods
Which of the following may be statically imported? (Choose two.)|Static method n
ames, Static field names
Which of the following may follow the static keyword? (Choose three.)|Data,
Methods, Code blocks enclosed in curly brackets
Which of the following may legally appear as the new type (between the parenthes
es) in a cast operation? (Choose one.)|All of the others
Which of the following may not be synchronized? (Choose one.)|Classes
Which of the following may override a method whose signature is void xyz(float f
)? (Choose two.)|void xyz(float f), public void xyz(float f)
Which of the following methods in the Thread class are deprecated?(Choose one.)|
suspend() and resume()
Which of the following operations might throw an ArithmeticException?(Choose one
.)|None of these
Which of the following operations might throw an ArithmeticException?(Choose one
.)|/
Which of the following operators can perform promotion on their operands? (Choos
e three.)|+ - ~
Which of the following restrictions apply to anonymous inner classes?(Choose one
.)|They must be defined inside a code block.
Which of the following should always be caught? (Choose one.)|Checked exceptions
Which of the following statements about the wait() and notify() methods is true?
(Choose one.)|The thread that calls wait() goes into the monitor s pool of waitin
g threads.
Which of the following statements about threads is true? (Choose one.)|Threads i
nherit their priority from their parent thread.
Which of the following statements are true? (Choose one.)|A final class may not
be extended.
Which of the following statements are true? (Choose one.)|Given that Inner is a
nonstatic class declared inside a public class Outer and that appropriate constr
uctor forms are defined, an instance of Inner can be constructed like this: new
Outer().new Inner()
Which of the following statements are true? (Choose one.)|None of the above
Which of the following statements are true? (Choose two.)|StringBuilder is gener
ally faster than StringBuffer., StringBuffer is threadsafe; StringBuilder is
not.
Which of the following statements are true? 1)An abstract class may not have any
final methods. 2)A final class may not have any abstract methods.|Only statemen
t 2
Which of the following statements is correct? (Choose one.)|Both primitives and
object references can be both converted and cast.
Which of the following statements is true? (Choose one.)|Transient variables are
not serialized.
Which of the following statements is true? (Choose one.)|Object references can b
e converted in both method calls and assignments, and the rules governing these
conversions are identical.
Which of the statements below are true? (Choose one.)|Unicode characters are all
16 bits.
Which statements about JDBC are NOT true? (choose 2)|JDBC is a Java database sy
stem., JDBC is a Java API for connecting to any kind of DBMS
Which two code fragments correctly create and initialize a static array of int e
lements? (Choose two.)|static final int[] a = { 100,200 }; static final i
nt[] a; static { a=new int[2]; a[0]=100; a[1]=200; }
Which two of the following interfaces are at the top of the hierarchies in the J
ava Collections Framework? (Choose two.)|Map Collection
Which of the following is legal import statement?|import java.util.Vector.*.*;
Which of the following code snippets does not compile?|int i = 7; byte b = i;
Which of the following signatures is valid for the main() method entry point of
an application?|public static void main(String arg[])
Which of the following will compile without error (select two)|package MyPackage
; import java.awt.*; class MyClass{}, /*This is a comment */ package
MyPackage; import java.awt.*; class MyClass{}
Which of the following will compile without error |package MyPackage; import j
ava.awt.*; class MyClass{}
Which of the following is an example of a bool-expression?|cause == bYes
Which of the following is an example of a bool-expression?|a==b
Which of the following is illegal statement?|float f=1.01;
When a short is added to a float, what is the type of the result?|float
What is the return type of the instanceof operator?|An boolean
Which of the following statements is true?|Object references can never be conver
ted.
Which of the following statements is true?|A class that has one abstract method
must be abstract class
We can access a static variable through the class name?|True
When you call start() method of a thread, the code inside method run() will run
immediately|False
Which is the last step of four-step approach to help you organize your GUI thin
king?|Choose layout managers.
Which of the following is NOT a swing component? |JText
Which of the following statements is true?|An abstract class may be inherited.
Study the statements: 1)When a JDBC connection is created, it is in auto-commi
t mode 2)Once auto-commit mode is disabled, no SQL statements will be committ
ed until you call the method commit explicitly|Both 1 and 2 are true
is a set of java API for executing SQL statements.|JDBC
SQL keyword ___ is followed by the selection criteria that specify the rows to s
elect in a query|WHERE
Select the most correct statement:|If a checked exception may be thrown within t
he body of a method, the method must either catch the exception or declare it in
its throws clause.
All of the numeric wrapper classes in the java.lang package are subclasses of t
he abstract class .|java.lang.Number
Which of the following is invalid wrapper class|java.lang.int
In order for objects in a List to be sorted, those objects must implement which
interface and method?|Comparable interface and its compareTo method.
See picture:|GridBagLayout
One way to approach the daunting number of Swing components is to divide them in
to three categories: Container components Ordinary components Menu componen
ts|True
Which of the following may override a method whose signature is void xyz(float f
)?|public void xyz(float f)
Which of the following is true?|An enum definition may contain the main() method
of an application.
Which of the following is VALID?|Vector <String> theVec = new Vector<String>();
Which of the following statement about inner class is true?|An anonymous inner c
lass may implement at most one interface.
Which of the following class implement java.util.List?|java.util.ArrayList
Which of the following statements are true? (select two)|An inner class may be d
efined as static, An inner class may be defined as static
Which of the following methods of the java.io.File can be used to create a new f
ile?|createNewFile()
Select INCORRECT statement about ServerSocket class.|To make the new object avai
lable for client connections, call its accept() method, which returns an instanc
e of ServerSocket
Which of the following statements are true? (Select two)|TCP provides a point-to
-point channel for applications that require reliable connections. UDP is a
protocol that sends independent packets of data, called datagrams, from one com
puter to another with no guarantee about arrival
Which of the following statements is INCORRECT?|All methods in an abstract class
must be declared as abstract
An abstract class |can contain all concrete methods.
______________ drivers that implement the JDBC API as a mapping to another data
access API, such as ODBC. Drivers of this type are generally dependent on a nati
ve library, which limits their portability.|Type 1
______ method is used to wait for a client to initiate communications|accept()
language and partly in native code. These drivers use a native client library sp
ecific to the data source to which they connect. Again, because of the native co
de, their portability is limited.|Type 2
____________ drivers that are pure Java and implement the network protocol for a
specific data source. The client connects directly to the data source.|Type 4
____________ drivers that use a pure Java client and communicate with a middlewa
re server using a database-independent protocol. The middleware server then comm
unicates the client's requests to the data source.|Type 3
______________ drivers that implement the JDBC API as a mapping to another data
access API, such as ODBC. Drivers of this type are generally dependent on a nati
ve library, which limits their portability.|Type 1
A _____ dialog prevents user input to other windows in the application unitl the
dialog is closed.|Modal
A Java monitor must either extend Thread or implement Runnable.|False
A monitor called mon has 10 threads in its waiting pool; all these waiting threa
ds have the same priority. One of the threads is thr1. How can you notify thr1 s
o that it alone moves from the Waiting state to the Ready state? (Choose one.)|Y
ou cannot specify which thread will get notified
A signed data type has an equal number of non-zero positive and negative values
available.|False
A thread wants to make a second thread ineligible for execution. To do this, the
first thread can call the yield() method on the second thread.|False
A(n) ___ object is used to submit a query to a database|Statement
A(n) ___ object is uses to obtain a Connection to a Database|DriverManager
Consider the following line of code: int[] x = new int[25]; |x[24] is 0
Given a string constructed by calling s = new String("xyzzy"), which of the call
s modifies the string? (Choose one.)| None of the above
Given arrays a1 and a2, which call returns true if a1 and a2 have the same lengt
h, and a1[i].equals(a2[i]) for every legal index i? |java.util.Arrays.equals(a1,
a2);
How can you ensure that multithreaded code does not deadlock? | There is no sing
le technique that can guarantee non-deadlocking code.
How can you force garbage collection of an object? (Choose one.) | Garbage colle
ction cannot be forced.
How do you prevent shared data from being corrupted in a multithreaded environme
nt? | Access the variables only via synchronized methods.
How do you use the File class to list the contents of a directory?| String[] con
tents = myFile.list();
How many locks does an object have? | One
If all three top-level elements occur in a source file, they must appear in whic
h order? | Package declaration, imports, class/interface/enum definitions.
If class Y extends class X, the two classes are in different packages, and class
X has a protected method called abby(), then any instance of Y may call the abb
y() method of any
other instance of Y.| False
If you need a Set implementation that provides value-ordered iteration, which cl
ass should you use? (Choose one.)|TreeSet
In order for objects in a List to be sorted, those objects must implement which
interface and method? (Choose one.)| Comparable interface and its compareTo met
hod.
Interface ____ helps manage the connection between a Java program and a database
.| Connection
Is it possible to write code that can execute only if the current thread owns |
Yes
JDBC supports ______ and ______ models. | Two-tier and three-tier
MVC is short call of | Model-View-Controller
Select correct statement about RMI. | All the above
Select correct statement(s) about remote class.(choose one) | All the others cho
ices
Select correct statements about remote interface | All the others choices
Select INCORRECT statement about serialization | When an Object Output Stream s
erializes an object that contains references to another object, every referenced
object is not serialized along with the original object.
Select INCORRECT statement about deserialize | We use readObject() method of Obj
ectOutputStream class to deserialize
Select incorrect statement about RMI server | A client accesses a remote object
by specifying only the server name.
Select incorrect statement about ServerSocket class | To make the new object ava
ilable for client connections, call its accept() method, which returns an instan
ce of ServerSocket
Select incorrect statement about Socket class | The java.net.Socket class contai
ns code that knows how to find and communicate with a server through UDP.
Select the correct statement about JDBC two-tier processing model. | A user's co
mmands are delivered to the database or other data source, and the results of th
ose statements are sent back to the user.
SQL keyword ___ is followed by the selection criteria that specify the rows to s
elect in a query | WHERE
Statement objects return SQL query results as ___ objects | ResultSet
Study the statements: 1)When a JDBC connection is created, it is in auto-commit
mode | Both 1 and 2 are true
Suppose a method called finallyTest() consists of a try block, followed by a cat
ch block, followed by a finally block. Assuming the JVM doesn t crash | If the JVM
doesn't crash and the code does not execute a System.exit() call, the finally b
lock will always execute.
Suppose a source file contains a large number of import statements and one class
definition. How do the imports affect the time required to load the class? | Cl
ass loading takes no additional time.
Suppose a source file contains a large number of import statements. How do the i
mports affect the time required to compile the source file? | Compilation takes
slightly more time.
Suppose class A extends Object; Class B extends A; and class C extends B. Of the
se, only class C implements java.io.Externalizable. Which of the following must
be true in order to avoid an exception during deserialization of an instance of
C? | C must have a no-args constructor.
Suppose class A has a method called doSomething(), with default access. Suppose
class B extends A and overrides doSomething(). Which access modes may not apply
to B s version of doSomething()? | private
Suppose prim is an int and wrapped is an Integer. Which of the following are leg
al Java statements? | All the above
Suppose salaries is an array containing floats. Which of the following are valid
loop control statements for processing each element of salaries? | for (float
f:salaries)
Suppose the declared type of x is a class, and the declared type of y is an inte
rface. When is the assignment x = y; legal? | When the type of x is Object
Suppose the type of xarr is an array of XXX | Sometimes
Suppose x and y are of type TrafficLightState, which is an enum. What is the bes
t way to test whether x and y refer to the same constant? | if (x == y)
Suppose you are writing a class that will provide custom deserialization. The cl
ass implements java.io.Serializable (not java.io.Externalizable). What access mo
de should the readObject() method have? |private
Suppose you are writing a class that will provide custom serialization. The clas
s implements java.io.Serializable (not java.io.Externalizable). What access mode
should the writeObject() method have | private
Suppose you want to create a custom thread class by extending java.lang.Thread i
n order to provide some special functionality. Which of the following must you d
o? | Override run().
Suppose you want to write a class that offers static methods to compute hyperbol
ic trigonometric functions. You decide to subclass java.lang.Math and provide th
e new functionality as a set of static methods. Which one statement is true abou
t this strategy |The strategy fails because you cannot subclass java.lang.Math
Swing components cannot be combined with AWT components.| True
The ______ class is the primary class that has the driver information | DriverMa
nager
The ______ class is used to implement a pull-down menu that provides a number of
items to select from | MenuBar
The element method alters the contents of a Queue. | False
The Swing component classes can be found in the ________________ package. | java
x.swing
There are two classes in Java to enable communication using datagrams namely. |
DataPacket and DataSocket
URL referring to databases use the form | protocol:subprotocol:datasoursename
What is the difference between the rules for method-call conversion and the rule
s for assignment conversion? | There is no difference; the rules are the same.
What is the return type of the instanceof operator? | A boolean
What method of the java.io.File class can create a file on the hard drive? | cr
eateNewFile()
When a byte is added to a char, what is the type of the result? | int
When a negative byte is cast to a long, what are the possible values of the resu
lt? | Negative
When a negative long is cast to a byte, what are the possible values of the resu
lt? | All the above
When a short is added to a float, what is the type of the result? | float
When comparing java.io.BufferedWriter to java.io.FileWriter, which capability ex
ists as a method in only one of the two? | writing a line separator to the strea
m
When does an exception's stack trace get recorded in the exception object? | Whe
n the exception is constructed
When is it appropriate to pass a cause to an exception's constructor? | When the
exception is being thrown in response to catching of a different exception type
When is it appropriate to write code that constructs and throws an error? | Neve
r
When is x & y an int? | Sometimes
When the user attempts to close the frame window, _______ event in generated | w
indow closing
When the user selects a menu item, _______ event is generated. | Action event
When you compile a program written in the Java programming language, the compile
r converts the human-readable source file into platform-independent code that a
Java Virtual Machine can understand. What is this platform-independent code call
ed?| bytecode
Whenever a method does not want to handle exceptions using the try block, the __
______ is used.| throws
Which class and static method can you use to convert an array to a List? | Arra
ys.asList
Which is four-step approach to help you organize your GUI thinking. | Identify
needed components.Isolate regions of behavior.Sketch the GUI.Choose layout manag
ers.
Which is the four steps are used in working with JDBC? | 1)Connect to the databa
se 2)Create a statement and execute the query 3)Look at the result set 4)Close c
onnection
Which JDBC processing model that requires a JDBC driver that can communicate wi
th the particular data source being accessed? | two-tier
Which line of code tells a scanner called sc to use a single digit as a delimite
r? | sc.useDelimiter("\\d");
Which Man class properly represents the relationship "Man has the best friend wh
o is a Dog"? | class Man { private Dog bestFriend; }
Which modifier or modifiers should be used to denote a variable that should not
be written out as part of its class's persistent state? | transient
Which of the following are methods of the java.util.SortedSet interface? | All t
he above
Which of the following are valid arguments to the DataInputStream constructor? |
FileInputStream
Which of the following are valid mode strings for the RandomAccessFile construct
or? | All the above
Which of the following calls may be made from a non-static synchronized method?
| All the above
Which of the following classes implement java.util.List? | java.util.ArrayList j
ava.util.Stack
Which of the following classes implements a FIFO Queue? |LinkedList
Which of the following interfaces does not allow duplicate objects? | Set
Which of the following is not appropriate situations for assertions? | Precondit
ions of a public method
Which of the following is NOTa valid comment: | /* comment
Which of the following is the most appropriate way to handle invalid arguments i
n a public method? | Throw java.lang.IllegalArgumentException
Which of the following is true? | None of the above
Which of the following may appear on the left-hand side of an instanceof operato
r? | A reference
hich of the following may legally appear as the new type (between the parenthese
s) in a cast operation? | All of the others
Which of the following may legally appear as the new type (between the parenthes
es) in a cast operation? | All of the above
Which of the following may not be synchronized? | Classes
Which of the following methods in the Thread class are deprecated? | suspend() a
nd resume()
Which of the following operations might throw an ArithmeticException? | None of
these
Which of the following operations might throw an ArithmeticException? | /
Which of the following operators can perform promotion on their operands? | =-~
Which of the following restrictions apply to anonymous inner classes? | They mus
t be defined inside a code block.
Which of the following should always be caught? | Checked exceptions
Which of the following statements about the wait() and notify() methods is true?
| The thread that calls wait() goes into the monitor s pool of waiting threads.
Which of the following statements about threads is true? | Threads inherit their
priority from their parent thread.
Which of the following statements are true?1)An abstract class may not have any
final methods.2)A final class may not have any abstract methods.| Only statement
2
Which of the following statements is correct? | Both primitives and object refer
ences can be both converted and cast.
Which of the following statements is true? | Transient variables are not seriali
zed.
Which of the following statements is true? | Object references can be converted
in both method calls and assignments, and the rules governing these conversions
are identical.
Which of the statements below are true? | Unicode characters are all 16 bits.
Which of the statements below are true? | None of the above
Which statements about JDBC are NOT true? | JDBC is a Java database system. and
JDBC is a Java API for connecting to any kind of DBMS
Which two of the following interfaces are at the top of the hierarchies in the J
ava Collections Framework? | Map and Collection
Which of the following operators might throw an ArithmeticException ? | /
Given arrays a1 and a2 which call returns true if a1 and a2 have the same length
, and a1[i] equais(a2[i]) for every legal index i | Java.util.Array.compare(a1,a
2)
Which of the following may legally appear as the new type (between the parenthes
es) in a cast operation ? | All of the others
Is it possible to define a class called Thing so that the following method can r
eturn true under certain circumstances?| Yes
Which of the following statements is true? | Object references can be converted
in both method calls and assignments, and the rules governing these conversions
are identical
What is the range of values that can be assigned to a variable of type byte?| -2
^7 through ^7-1
A signed data type has an equal number of non-zero positive and negative values
available.| False
Which of the following statements is true? | Transient variables are not seriali
zed.
Which of the following statements is correct? | Both primitives and object refer
ences can be both converted and cast.
Which of the following are valid declarations? Assume java.util.* is imported.
|Vector<Map> v;Set<String> ;Map<String, String> m;\
You can determine all the keys in a Map in which of the following ways |By get
ting a Set object from the Map and iterating through it.
What keyword is used to prevent an object from being serialized|D. transien
t
An abstract class can contain methods with declared bodies|true
Select the order of access modifiers from least restrictive to most restrictive|
E. public, protected, default, private
Which access modifier allows you to access method calls in libraries not create
d in Java|A. native
Which of the following statements are true? (Select all that apply|D. A final
object cannot be reassigned a new address in memory
The keyword extends refers to what type of relationship|G. is a
Which of the following keywords is used to invoke a method in the parent clas
s?|super
public class Funcs extends java.lang.Math|C. The code does not compile.
public class Test |D. The code does not compile.
What is the value of x after the following operation is performed x = 23 %
4;|3
Given the following code, what keyword must be used at line 4 in order to stop
execution of the for loop?|C. break
What method call is used to tell a thread that it has the opportunity to run?
|B. notify()
interface Box |A. The code will not compile because of line 4.
Assertions are used to enforce all but which of the following|C. Exceptio
ns
The developer can force garbage collection by calling System.gc().|false
Select the valid primitive data types. (Select all that apply.)|boolean char flo
at
How many bits does a float contain|32
What is the value of x after the following line is executed? x = 32 * (31 -
10 * 3);|32
A StringBuffer is slower than a StringBuilder, but a StringBuffer is threadsafe
|true
Select the list of primitives ordered in smallest to largest bit size represent
ation|D. char, int, float, long
Which class provides locale-sensitive text formatting for date and time informat
ion?|D. java.text.DateFormat
The following line of code is valid. int x = 9; byte b = x;|false
Which of the following code snippets compile|Integer i = 7; Integer i = new In
teger(5); int j = i;byte b = 7;
public class StringTest |D. same will be printed out to the console.
Java arrays always start at index 1|false
which of the following statements accurately describes how variables are passe
d to method|C. Arguments that are primitive type are passed by value.
How do you change the value that is encapsulated by a wrapper class after you
have instan- tiated it|D. None of the above
Suppose you are writing a class that provides custom deserialization. The class
implements java.io.Serializable (and not java.io.Externalizable). What method s
hould imple- ment the custom deserialization, and what is its access mode?|A.
private readObject
A signed data type has an equal number of non-zero positive and negative value
s available.|fasle
Choose the valid identifiers from those listed here. (Choose all that apply |Big
OlLongStringWithMeaninglessName - $int - bytes - $1 - finalist
Which of the following signatures are valid for the main() method entry point of
an application?(Choose all that apply.) |public static void main(String arg[])
- public static void main(String[] args)
If all three top-level elements occur in a source file, they must appear in whi
ch order?|D. Package declaration, imports, class/interface/enum definitions.
Consider the following line of code:int[] x = new int[25]; After execution, w
hich statements are true? (Choose all that apply.)|A. x[24] is 0 - E. x.length
is 25
class Q6 |101
class Q7 |12.3
How can you force garbage collection of an object|A. Garbage collection cann
ot be forced
What is the range of values that can be assigned to a variable of type short?|-2
15 through 215 - 1
What is the range of values that can be assigned to a variable of type byte|-27
through 27 - 1
Suppose a source file contains a large number of import statements. How do the
imports affect the time required to compile the source file?|B. Compilat
ion takes slightly more time.
Suppose a source file contains a large number of import statements and one cl
ass definition. How do the imports affect the time required to load the class?
|A. Class loading takes no additional time.
Which of the following are legal import statements|import java.util.Vector - im
port static java.util.Vector.*;
Which of the following may be statically imported? (Choose all that apply.)|Stat
ic method names-Static field names
public class Q15 |C. The code compiles, and prints out >>null<<
The code compiles, and prints out >>null<<|C. int c = 0xabcd- C. int c =
0xabcd
Which of the following are legal? (Choose all that apply.) |A. double d = 1.2
d; - B. double d = 1.2D;
Which of the following are legal?|A. char c = \u1234 ;
Consider the following code: StringBuffer sbuf = new StringBuffer(); sbuf = nu
ll; System.gc();|C. After line 2 executes, the StringBuffer object is eligib
le for garbage collection.
Which of the following are true? (Choose all that apply.)|B. Primitives are p
assed by value. - D. References are passed by value.
After execution of the following code fragment, what are the values of the var
iables x, a, and b? int x, a = 6, b = 7; x = a++ + b++; |C. x = 13, a = 7, b
= 8
Which of the following expressions are legal? (Choose all that apply.)|B.
int x = 6; if (!(x > 3)) {} - C. int x = 6; x = ~x;
Which of the following expressions results in a positive value in x? |A.
int x = 1; x = x >>> 5;
Which of the following expressions are legal? (Choose all that apply.)|tring x
= "Hello"; int y = 9; x += y; - C. String x = "Hello"; int y = 9; x =
x + y;
What is -8 % 5? | -3
What is 7 % -4? | 3
public class Xor |B. The output: b contains 5
public class Conditional |C. The output: value is 9.0
What does the following code do? Integer i = null; if (i != null & i.int
Value() == 5) System.out.println( Value is 5 ); |B. Throws an exception
Is it possible to define a class called Thing so that the following method can
return true under certain circumstances? boolean weird(Thing s) { Integer x
= new Integer(5); return s.equals(x); } |yes
Suppose ob1 and ob2 are references to instances of java.lang.Object. If (ob1 =
= ob2) is false, can ob1.equals(ob2) ever be true? |no
When a byte is added to a char, what is the type of the result? |int
When a short is added to a float, what is the type of the result? |float
Which statement is true about the following method? int selfXor(int i) { retur
n i ^ i;} |A. It always returns 0.
Which of the following operations might throw an ArithmeticException? |D.
None of these
Which of the following operations might throw an ArithmeticException? | /
Which of the following operations might throw an ArithmeticException? | a boole
an
Which of the following may appear on the left-hand side of an instanceof opera
tor? |A. A reference
Which of the following may appear on the right-hand side of an instanceof operat
or? (Choose all that apply.)|B. A class -C. An interface
What is -50 >> 1? | -25
Which of the following declarations are illegal? (Choose all that apply.)|A.
default String s; - D. abstract double d; - D. abstract double d;
Which of the following statements is true? | B. A final class may not ha
ve any abstract methods.
final class Aaa| A. On line 1, remove the final modifier.
Which of the following statements is true? |E. Transient variables are not seri
alized.
class StaticStuff |E. The code compiles and execution produces the output x
= 3.
class HasStatic |E. The program compiles and the output is x = 104.
class SuperDuper |D. line 3: private; line 8: protected
Which modifier or modifiers should be used to denote a variable that should not
be written out as part of its class s persistent state? (Choose the shortest pos
sible answer.) |D. transient
public class Bird |C. Compilation of Parrot.java fails at line 7 because metho
d getRefCount() is static in the superclass, and static methods may not be ove
rridden to be nonstatic.
class Nightingale extends abcde.Bird |A. The program will compile and exe
cute. The output will be Before: 0 After: 2.
Suppose class Supe, in package packagea, has a method called doSomething(). Supp
ose class Subby, in package packageb, overrides doSomething(). What access mod
es may Subby s version of the method have? (Choose all that apply.) |public - pr
otected
Which of the following statements are true |F. None of the above
Suppose interface Inty defines five methods. Suppose class Classy declares that
it implements Inty but does not provide implementations for any of the five int
erface methods. Which is/are true?|The class will compile if it is declared abst
ract.- The class may not be instantiated.
Which of the following may be declared final? (Choose all that apply.) |Classes
- Data - Methods
Which of the following may follow the static keyword? (Choose all that apply.)
|Data - Methods - Code blocks enclosed in curly brackets
Suppose class A has a method called doSomething(), with default access. Suppose
class B extends A and overrides doSomething(). Which access modes may apply to
B s version of doSomething()? (Choose all that apply.) |public - protected - Defa
ult
True or false: If class Y extends class X, the two classes are in different pack
ages, and class X has a protected method called abby(), then any instance of Y
may call the abby() method of any other instance of Y. | false
Which of the following statements are true? |D. A final class may not be
extended.
Which of the following statements are true | D. A final class may not be
extended.
public class A | -1
Which of the following statements is correct? (Choose one.) |Both primitives an
d object references can be both converted and cast.
Which one line in the following code will not compile? |F. Line 6
Will the following code compile? ||E. int, long, float, double
class Cruncher | D. The code will compile and produce the following output:
int version
Which of the following statements is true? (Choose one |D. Object reference
s can be converted in both method calls and assignments, and the rules govern
ing these conversions are identical.
Consider the following code. Which line will not compile? |C. Line 6
Consider the following code |The code will compile and run.
Cat sunflower |The code will compile but will throw an exception at line 7, b
ecause the runtime class of wawa cannot be converted to type SwampThing.
Raccoon rocky; |Line 7 will not compile; an explicit cast is required to conv
ert a Washer to a SwampThing
Which of the following may legally appear as the new type (between the parenthe
ses) in a cast operation | All of the above
Which of the following may legally appear as the new type (between the parenthe
ses) in a cast operation? | D. All of the above
Suppose the declared type of x is a class, and the declared type of y is an inte
rface. When is the assignment x = y; legal? |A. When the type of x is Ob
ject
Suppose the type of xarr is an array of XXX, and the type of yarr is an array of
YYY. When is the assignment xarr = yarr; legal? |A. Sometimes
When is x & y an int? (Choose one). | sometimes
What are the legal types for whatsMyType? short s = 10; whatsMyType = !s; | C.
There are no possible legal types
When a negative long is cast to a byte, what are the possible values of the resu
lt |D. All of the above
When a negative byte is cast to a long, what are the possible values of the resu
lt? | Negative
Which of the following operators can perform promotion on their operands? (Choo
se all that apply.) | + - ~
What is the difference between the rules for method-call conversion and the rule
s for assignment conversion? | A. There is no difference; the rules are th
e same
for (int i = 0; i < 2; i++) | i = 0 j = 1 - i = 0 j = 2 - i = 1 j = 0
- i = 1 j = 2
outer: for (int i = 0; i < 2; i++) | outer: for (int i = 0; i < 2; i++)
Which of the following are legal loop constructions? (Choose all that apply.) |
int j = 0; for (int k=0, j+k != 10; j++,k++) { System.out.println("j=" +
j + ", k=" + k); }
What would be the output from this code fragment | message four
int j = 2; | D. The output would be the text value is two followed by the text v
alue is three.
What lines are output if the method at line 5 throws an OutOfMemoryError? (Choos
e all that apply.) |E. Doing finally part
Which of the following are appropriate situations for assertions |Postconditions
of a public method - Preconditions of a private method - Postconditions of a pr
ivate method
Which of the following is the most appropriate way to handle invalid arguments
in a public method? | B. Throw java.lang.IllegalArgumentException.
Suppose salaries is an array containing floats. Which of the following are vali
d loop control statements for processing each element of salaries? - for (float
f:salaries)
Which of the following are legal? (Choose all that apply.)|for (int i=0, j=1; i
<10; i++, j++) - for (int i=0, j=1;; i++, j++) - for (String s = ;
s.length()<10
; s += ! )
Suppose a method called finallyTest() consists of a try block, followed by a ca
tch block, followed by a finally block. Assuming the JVM doesn t crash and the cod
e does not execute a System.exit() call, under what circumstances will the fina
lly block not begin to execute? - D. If the JVM doesn t crash and the code does
not execute a System.exit() call, the finally block will always execute.
Which of the following are legal loop definitions? (Choose all that apply.) | N
one of them are legal.
Which of the following are legal argument types for a switch statement? | byte-
int - char
When is it appropriate to pass a cause to an exception s constructor | B.
When the
exception is being thrown in response to catching of a different exception ty
pe
Which of the following should always be caught? | B. Checked exceptions
When does an exception s stack trace get recorded in the exception object? | A.
When the exception is constructed
When is it appropriate to write code that constructs and throws an error? |neve
r
public class Test1 | public int aMethod(int a, int b) { } - public float
aMethod(float a, float b, int c) throws Exception { }- private float aMethod(i
nt a, int b, int c) { }
public class Test1 |public int aMethod(int a, int b) throws Exception {...}
- public float aMethod(float p, float q) {...}
A pet has an owner, a registration date, and a vaccination-due date. A cat is a
pet that has a flag indicating whether it has been neutered, and a textual de
scription of its markings. | boolean neutered - String markings
A pet has an owner, a registration date, and a vaccination-due date. A cat is a
pet that has a flag indicating if it has been neutered, and a textual descript
ion of its markings | public class Cat extends Pet
public class Base | Value is 5This value is 6
public class Test extends Base | Test t = new Test(1); Test t = new Test(1, 2
);
public class Test extends Base |Base() { } - Base(int j, int k) { }
public class Outer | a- b - c -e
Which of the following statements are true? (Choose all that apply.)|Given that
Inner is a nonstatic class declared inside a public class Outer and that appro-
priate constructor forms are defined, an instance of Inner can be constructed l
ike this: new Outer().new Inner()
Which of the following are legal enums | enum Animals {LION, TIGER, BEAR; int
weight;} - enum Animals {LION(450), TIGER(450), BEAR; int weight;Animals() { }
Animals(int w) {weight = w;}}
Which of the following may override a method whose signature is void xyz(float
f)? |void xyz(float f) - public void xyz(float f)
Which of the following are true? (Choose all that apply.) |An enum may contain
public method definitions. - An enum may contain private data.
Which of the following are true? (Choose all that apply.) |An enum definition m
ay contain the main() method of an application. - You can call an enum s toStrin
g() method. - You can call an enum s wait() method. - You can call an enum s
notify(
) method.
Suppose x and y are of type TrafficLightState, which is an enum. What is the bes
t way to test whether x and y refer to the same constant | A. if (x == y)
Which of the following restrictions apply to anonymous inner classes? | They mus
t be defined inside a code block.
Given the following code, which of the following will not compile? enum Spice {
NUTMEG, CINNAMON, CORIANDER, ROSEMARY; } |String ob = new String(); Spice
sp = ob;
Which of the following are true |An anonymous inner class may implement at most
one interface. - An anonymous inner class may extend a parent class other than
Object
Which methods return an enum constant s name | name() - toString()
Suppose class X contains the following method: void doSomething(int a, float b)
{ } Which of the following methods may appear in class Y, which extends
X?|public void doSomething(int a, float b) { }
This question involves IOException, AWTException, and EOFException. They are al
l checked exception types. IOException and AWTException extend Exception, and EO
FException extends IOException. Suppose class X contains the following method:
void doSomething() throws IOException{ }|void doSomething() { } -
void
doSomething() throws EOFException { } - void doSomething() throws IOExce
ption, EOFException { }
class Greebo extends java.util.Vector |There will be a compiler error, becaus
e class Greebo does not correctly implement the Runnable interface.
class HiPri extends Thread |C. When the application is run, all three threads (
hp1, hp2, and hp3) will execute concurrently, taking time-sliced turns in the CP
U.
A thread wants to make a second thread ineligible for execution. To do this,
the first thread can call the yield() method on the second thread. | false
A thread s run() method includes the following lines: | D. At line 2, the t
hread will stop running. It will resume running some time after 100 milliseconds
have elapsed.
A monitor called mon has 10 threads in its waiting pool; all these waiting threa
ds have the same priority. One of the threads is thr1. How can you notify thr1
so that it alone moves from the Waiting state to the Ready state? |E. You cann
ot specify which thread will get notified.
class TestThread3 extends Thread |yes
A Java monitor must either extend Thread or implement Runnable.|fasle
Which of the following methods in the Thread class are deprecated|A. suspend(
) and resume()
Which of the following statements about threads is true?|B. Threads inherit
their priority from their parent thread.
Threads inherit their priority from their parent thread.|C. The thread that
calls wait() goes into the monitor s pool of waiting threads.
The thread that calls wait() goes into the monitor s pool of waiting threads. |c
lasses
Which of the following calls may be made from a non-static synchronized method?
| all
How many locks does an object have?|One
is it possible to write code that can execute only if the current thread owns
multiple locks?|yes
Which of the following are true? (Choose all that apply.) |there is one non-daem
on thread - A thread created by a daemon thread - A thread created by a non-
daemon thread
Which of the following are true? |D. The JVM runs until there are no non-daem
on threads.
How do you prevent shared data from being corrupted in a multithreaded environme
nt? |D. Access the variables only via synchronized methods.
How can you ensure that multithreaded code does not deadlock|A, B, and C do not
ensure that multithreaded code does not deadlock.
Which of the following are true? (Choose all that apply |When you declare a meth
od to be synchronized, the method - When you declare a block of code inside a me
thod to be synchronized, you can
Suppose you want to create a custom thread class by extending java.lang.Thread
in order to provide some special functionality. Which of the following must you
do? |Override run().
Given a string constructed by calling s = new String( xyzzy ), which of the calls
mo
difies the string? | none of the above
String s1 = abc + def ; | Line 6 executes and line 4 does not.
Suppose you want to write a class that offers static methods to compute hyperbol
ic trigonometric functions. You decide to subclass java.lang.Math and provide t
he new functionality as a set of static methods. Which one statement is true ab
out this strategy | D. The strategy fails because you cannot subclass java.lan
g.Math
import java.lang.Math; | Compilation fails at line 2.
String s = abcde ; | Compilation succeeds. No exception is thrown during execution
.
StringBuffer sbuf = new StringBuffer( abcde );|true
String s1 = xyz ; String s2 = xyz ;| true
String s1 = xyz ; String s2 = new String(s1);| false
Suppose prim is an int and wrapped is an Integer. Which of the following are le
gal Java statements? (Choose all that apply.) |prim = wrapped; - wrapped =
prim; - prim = new Integer(9); - wrapped = 9;
Which of the following are legal? (Choose all that apply.) |List<String> theList
= new Vector<String>(); - Vector <String> theVec = new Vector<String>();
Map<String> names = new HashMap<String>(); | Iterator<String> iter = names.ite
rator(); - for (String s:names)
Which of the following are legal clone() methods in a class called Q13 that ext
ends Object |public Object clone() throws CloneNotSupportedException { return s
uper.clone(); } - D. public Q13 clone() throws CloneNotSupportedException {
return (Q13)super.clone(); }
Which of the following classes implement java.util.List |java.util.ArrayList -
java.util.Stack
Which of the following are methods of the java.util.SortedSet interface?|first
- last - headSet - tailSet - subSet
Which of the following are methods of the java.util.SortedMap interface?|headMa
p- tailMap - subMap
Which line of code tells a scanner called sc to use a single digit as a delimite
r?|sc.useDelimiter( \\d );
public class Apple |C. An exception is thrown at line 7.
Given arrays a1 and a2, which call returns true if a1 and a2 have the same leng
th, and a1[i].equals(a2[i]) for every legal index i?|A. java.util.Arrays.equals(
a1, a2);
Which of the following statements are true?|A. StringBuilder is generally faste
r than StringBuffer. - StringBuilder is generally faster than StringBuffer.
Which of the statements below are true? (Choose all that apply | D. Unicode
characters are all 16 bits.
Which of the statements below are true? (Choose all that apply.)|D. None of
the above.
How do you use the File class to list the contents of a directory? |A. String[]
contents = myFile.list();
How many bytes does the following code write to file dest? |12
FileOutputStream fos = new FileOutputStream( xx ); | B. The output is i = 20.
FileOutputStream fos = new FileOutputStream( datafile ); |Construct a
FileInputStrea
m - Construct a RandomAccessFile,
Which of the following is true about Readers have methods that can read ? |None
of the above
File f1 = new File( dirname ); | E. No directory is created, and no file is
create
d.
Assume that the code fragment is part of an application that has write permissio
n in the current working directory. Also assume that before execution, the cur
rent working directory does not contain a file called datafile. | A.
The code fails to compile
Suppose you are writing a class that will provide custom serialization. The clas
s implements java.io.Serializable (not java.io.Externalizable). What access mode
should the writeObject() method have? |private
Suppose you are writing a class that will provide custom deserialization. The cl
ass implements java.io.Serializable (not java.io.Externalizable). What access m
ode should the readObject() method have? | private
Suppose class A extends Object; class B extends A; and class C extends B. Of the
se, only class C implements java.io.Serializable. Which of the following must be
true in order to avoid an exception during deserialization of an instance of C
? |B. B must have a no-args constructor.
Suppose class A extends Object; Class B extends A; and class C extends B. Of the
se, only class C implements java.io.Externalizable. Which of the following must
be true in order to avoid an exception during deserialization of an instance of
C? | C. C must have a no-args constructor.
public class Xyz implements java.io.Serializable |iAmPublic - iAmPrivate - iAmVo
latile
What method of the java.io.File class can create a file on the hard drive |crea
teNewFile()
public class Xxx |B. An exception is thrown at line 9.
Which of the following are valid mode strings for the RandomAccessFile construct
or? (Choose all that apply.) | r - rw - rws - rwd
Which of the following are valid arguments to the DataInputStream constructor?
| C. FileInputStream
public enum Wallpaper |Wallpaper wp = Wallpaper.BLUE; - void aMethod(Wallpaper
wp) { System.out.println(wp);} - int hcode = Wallpaper.BLUE.hashCode();
class Sploo | b - d - fff()
public abstract class Abby |SubAbby generates a compiler error. - If SubAbby wer
e declared abstract, it would compile without error. - Abby is a legal type for
variables.
class Xxx | heights is initialized to a reference to an array with zero elements
Given a class with a public variable theTint of type Color, which of the followi
ng methods are consistent with the JavaBeans naming standards? | public Color g
etTheTint()
Which of the following statements are true regarding the following method? voi
d callMe(String names) { } | Within the method, names is an array containing
Strings.
public class Food |Fruit - Citrus - Pomelo
class A extends java.util.Vector |The compiler does not create a default const
ructor.
Which of the following types are legal arguments of a switch statement | enums
- bytes
int[] ages = { 9, 41, 49 }; int sum = 0; |for (int i=0; i<ages.length; i++)
sum += ages[i]; - for (int i:ages) sum += i;
Which lines check that x is equal to four? Assume assertions are enabled at com
pile time and runtime. | assert x == 4; - assert x == 4 : x is not 4 ;
Which are appropriate uses of assertions |Checking preconditions in a private me
thod - Checking postconditions in a private method - Checking postconditions in
a public method
void callMe() throws ObjectStreamException | void callMe() - void callMe() thro
ws NotSerializableException
NotSerializableException extends ObjectStreamException. AWTException does not ex
tend any of these. All are checked exceptions. The callMe() method throws Not
SerializableException| Object Stream - Finally
While testing some code that you are developing, you notice that an ArrayIndexO
utOf- BoundsException is thrown. What is the appropriate reaction? | none of the
above
How is IllegalArgumentException used? (Choose all correct options.) | It is thro
wn by certain methods - It should be used by programmers to indicate that precon
ditions of public
Suppose shorty is a short and wrapped is a Short. Which of the following are leg
al Java state- ments? (Choose all correct options.)| shorty = wrapped; - wrappe
d = shorty; - shorty = new Short((short)9); - shorty = 9;
Which of the following statements are true? (Choose all correct options.) | Str
ingBuilder encapsulates a mutable string. - StringBuffer is threadsafe.
The file contains lines of 8-bit text, and the 8-bit encoding represents the lo
cal character set, as represented by the cur- rent default locale | C. Create a
FileReader instance. Pass it into the constructor of LineNumberReader. Use Lin
eNumberReader s readLine() method.
What interfaces can be implemented in order to create a class that can be serial
ized? (Choose all that apply.) | java.io.Serializable. There are no methods - ja
va.io.Externalizable, which defines two methods: readExternal
Suppose you are writing a class that will provide custom deserialization. The cl
ass implements java.io.Serializable (not java.io.Externalizable). What access m
ode should the readObject() method have? | private
Suppose you want to create a class that compiles and can be serialized and deser
ialized without causing an exception to be thrown. Which statements are true r
egarding the class? (Choose all correct options.) | java.io.Externalizable, it
must have a no-args - java.io.Serializable and does not implement
Suppose you want to use a DateFormat to format an instance of Date. What facto
rs influence the string returned by DateFormat s format() method? |The style, whic
h is one of SHORT, MEDIUM, LONG, or FULL - The locale
How do you generate a string representing the value of a float f in a format a
ppropriate for a locale loc? | NumberFormat nf = NumberFormat.getInstance(loc)
;
String scanMe = aeiou9876543210AEIOU ; | String delim = \\d+ ;
Which line prints double d in a left-justified field that is 20 characters wide,
with 15 characters to the right of the decimal point? | System.out.format("%-20
.15f", d);
Suppose MyThread extends java.lang.Thread, and MyRunnable implements java.lang.
Runnable (but does not extend Thread). Both classes have no-args constructors. W
hich of the following cause a thread in the JVM to begin execution? (Choose al
l correct options.)|(new MyThread()).start(); - (new Thread(new MyRunnable()))
(new Thread(new MyRunnable())) | The code prints Going to sleep, then Waking up,
and then All done.
Suppose threads aThread and bThread are both accessing a shared object named sh
aredOb, and aThread has just executed: sharedOb.wait(); |aThread.interrupt(); -
sharedOb.notifyAll();
Suppose class Home has methods chopWood() and carryWater(); it also has a metho
d called chopWoodAndCarryWater(), which just calls the other two methods. Whic
h statements are true? (Choose all that apply.) | chopWoodAndCarryWater() is an
example of inappropriate cohesion. - chopWoodAndCarryWater() is an example of i
nappropriate coupling.
Lemon lem = new Lemon(); Citrus cit = new Citrus(); |cit = lem; - lem = (Lem
on)cit; - cit = (Citrus)lem;
Grapefruit g = new Grapefruit(); | The cast in line 2 is not necessary. - The c
ast in line 2 is not necessary.
Suppose class aaa.Aaa has a method called callMe(). Suppose class bbb.Bbb, which
extends aaa.AAA, wants to override callMe(). Which access modes for callMe() i
n aaa.AAA will allow this? |public - protected
class Animal | B. Class Zebra generates a compiler error
class Xyz | super(); - this(1.23f);
What relationship does the extends keyword represent? | is a
When should objects stored in a Set implement the java.util.Comparable interfac
e | D. When the Set is a TreeSet
class Xyzzy |public int hashCode() { return a; } - public int hashCode()
{ return (int)Math.random();}
plainVec; Vector<String> fancyVec; |Attempting to add anything other than a st
ring to fancyVec results in a compiler error.
The declaration of the java.util.Collection interface is interface Collection <
E> |D. public boolean addAll(Collection<? extends E> c)
package ocean; public class Fish |B. public void swim() { } - size = 12;
public class App | 4
public class Wrapper | C. n is 10, w.x is 11
String s = aaa ; | A. After line 3
java -classpath somewhere;elsewhere aaa.bbb.MyApplication|Class MyApplication m
ust contain the statement package aaa.bbb;. - D. The file MyApplication.c
lass must be found either in somewhere\aaa\bbb or in elsewhere\aaa\bbb. (Substit
ute forward slashes for backslashes on a Unix system
What is -15 % -10? | -5
is a set of java API for executing SQL statements.| JDBC
method is used to wait for a client to initiate communications.|accept()
drivers that are written partly in the Java programming language and partly in n
ative code. These drivers use a native client library specific to the data sourc
e to which they connect. Again, because of the native code, their portability is
limited.|type 2
drivers that are pure Java and implement the network protocol for a specific dat
a source. The client connects directly to the data source.|type 4
drivers that use a pure Java client and communicate with a middleware server usi
ng a database-independent protocol. The middleware server then communicates the
client's requests to the data source. |type 3
drivers that implement the JDBC API as a mapping to another data access API, suc
h as ODBC. Drivers of this type are generally |type 1
public class A |Line 26 prints a to System.out.
public class A |The code on line 29 will be executed. - The exception will be pr
opagated back to line 27.
try { |Bad URL - Doing finally part - Carrying on
interface Foo |The code compiles and the output is 2. - If lines 16, 17 and 18 w
ere removed, the code would compile and the output would be 2. - If lines 24, 25
and 26 were removed, the code would compile and the output would be 1.
public class ClassA |An exception is thrown at runtime
public class Bootchy |third second first snootchy 420
A dialog prevents user input to other windows in the application unitl th
e dialog is closed. |modal
A Java monitor must either extend Thread or implement Runnable. | false
A monitor called mon has 10 threads in its waiting pool; all these waiting threa
ds have the same priority. One of the threads is thr1. How can you notify thr1 s
o that it alone moves from the Waiting state to the Ready state? (Choose one.) |
You cannot specify which thread will get notified.
A programmer needs to create a logging method that can accept an arbitrary numbe
r of arguments. For example, it may be called in these | public void logIt(Strin
g... msgs)
A signed data type has an equal number of non-zero positive and negative values
available.|false
A thread wants to make a second thread ineligible for execution. To do this, the
first thread can call the yield() method on the second thread.|false
try { |At line 2, the thread will stop running. It will resume running some time
after 100 milliseconds have elapsed
A(n) object is used to submit a query to a database |statement
A(n) object is uses to obtain a Connection to a Database |Drivermanager
After execution of the following code fragment, what are the values of the varia
bles x, a, and b? 1. int x, a = 6, b = 7; 2. x = a++ + b++;|x = 13, a = 7, b = 8
public class Money |Euro returns correct Country value. - Compilation fails beca
use of an error at line 25
public class SomeException |Compilation of class B will fail. Compilation of cla
ss A will succeed
public class TestException extends Exception |Line 46 will compile if the enclos
ing - Line 46 will compile if enclosed.
class Q6 |101
class Q7 |12.3
public class Test extends Base |Test t = new Test(1); - Test t = new Test(1, 2);
public class Test extends Base |Base() { } - Base(int j, int k) { }
class Cruncher |The code will compile and produce the following output: int vers
ion
Object ob = new Object(); |line 6
public class Assertification |The application must be - The args array must have
one or more elements.
StringBuffer sbuf = new StringBuffer();|After line 2 executes, the StringBuffer
object is eligible for garbage collection.
Cat sunflower;|The code will compile but will throw an exception at line 7, beca
use the runtime class of wawa cannot be converted to type SwampThing.
Select correct statement(s) about remote class.(choose one)|All the others choic
es
Select correct statements about remote interface. (choose 1)|All the others choi
ces
Select INCORRECT statement about serialization. (choose 1|When an Object Output
Stream serializes an object that contains references to another object, every r
eferenced object is not serialized along with the original object
Select INCORRECT statement about deserialize. (choose 1)|We use readObject() met
hod of ObjectOutputStream class to deserialize.
Select incorrect statement about RMI server.(choose 1)|A client accesses a remot
e object by specifying only the server name
Select incorrect statement about ServerSocket class. (choose 1)|To make the new
object available for client connections, call its accept() method, which returns
an instance of ServerSocket
Select incorrect statement about Socket class. (choose 1) |The java.net.Socket c
lass contains code that knows how to find and communicate with a server through
UDP.
Select the correct statement about JDBC two-tier processing model|A user's comma
nds are delivered to the database or other data source, and the results of those
statements are sent back to the user.
SQL keyword is followed by the selection criteria that specify the rows to
select in a query |Where
Statement objects return SQL query results as objects|ResultSet
When a JDBC connection is created, it is in auto-commit mode 2)Once auto-commit
mode is disabled, no SQL statements will be committed until you call the method
commit explicitly|Both 1 and 2 are true Suppose a method called finallyTest() co
nsists of a try block, followed by a catch block, followed by a finally block. A
ssuming the JVM doesn t crash and the code does not execute a System.exit() call,
under what circumstances will the finally block not begin to execute?|If the JVM
doesn't crash and the code does not execute a System.exit() call,the finally bl
ock will always execute.
Suppose a source file contains a large number of import statements and one class
definition. How do the imports affect the time required to load the class? (Cho
ose one.)|Class loading takes no additional time.
Suppose a source file contains a large number of import statements. How do the i
mports affect the time required to compile the source file? (Choose one.|Suppose
a source file contains a large number of import statements. How do the imports
affect the time required to compile the source file? (Choose one.)
Suppose class A extends Object; Class B extends A; and class C extends B. Of the
se, only class C implements java.io.Externalizable. Which of the following must
be true in order to avoid an exception during deserialization of an instance of
C? (Choose one.)|C must have a no-args constructor.
Suppose class A extends Object; class B extends A; and class C extends B. Of the
se, only class C implements java.io.Serializable. Which of the following must be
true in order to avoid an exception during deserialization of an instance of C?
(Choose one.)|B must have a no-args constructor.
Suppose class A has a method called doSomething(), with default access. Suppose
class B extends A and overrides doSomething(). Which access modes may not apply
to B s version of doSomething()? (Choose one)|private
Suppose class Supe, in package packagea, has a method called doSomething(). Supp
ose class Subby, in package packageb, overrides doSomething(). What access modes
may Subby s version of the method have? (Choose two.)|public - protected
Suppose class X contains the following method: void doSomething(int a, float b)
{ } Which of the following methods may appear in class Y, which extends X? (Choo
se one.)|public void doSomething(int a, float b) { }
Suppose interface Inty defines five methods. Suppose class Classy declares that
it implements Inty but does not provide implementations for any of the five inte
rface methods. Which are true? (Choose two.)|The class will compile if it is dec
lared abstract. The class may not be instantiated.
Suppose prim is an int and wrapped is an Integer. Which of the following are leg
al Java statements? (Choose one.)|All the above
Suppose salaries is an array containing floats. Which of the following are valid
loop control statements for processing each element of salaries? (Choose one.)|
for (float f:salaries)
Suppose the declared type of x is a class, and the declared type of y is an inte
rface. When is the assignment x = y; legal? (Choose one.)|When the type of x is
Object
Suppose the type of xarr is an array of XXX, and the type of yarr is an array of
YYY. When is the assignment xarr = yarr; legal? (Choose one.)|Sometimes
Suppose x and y are of type TrafficLightState, which is an enum. What is the bes
t way to test whether x and y refer to the same constant? (Choose one.)|if (x ==
y)
Suppose you are writing a class that will provide custom deserialization. The cl
ass implements java.io.Serializable (not java.io.Externalizable). What access mo
de should the readObject() method have? (Choose one.)|private
Suppose you are writing a class that will provide custom serialization. The clas
s implements java.io.Serializable (not java.io.Externalizable). What access mode
should the writeObject() method have? (Choose one.)|private
Suppose you want to create a custom thread class by extending java.lang.Thread i
n order to provide some special functionality. Which of the following must you d
o? (Choose one.)|Override run().
Suppose you want to write a class that offers static methods to compute hyperbol
ic trigonometric functions. You decide to subclass java.lang.Math and provide th
e new functionality as a set of static methods. Which one|The strategy fails bec
ause you cannot add static methods to a subclass.
Swing components cannot be combined with AWT components.|true
The class is the primary class that has the driver information.|DriverManag
er
The class is used to implement a pull-down menu that provides a number of i
tems to select from.|menu
The element method alters the contents of a Queue.|false
The Swing component classes can be found in the package.|javax.swing
There are two classes in Java to enable communication using datagrams namely.|Da
taPacket and DataSocket
public class Bird|Compilation of Parrot.java fails at line 7 because method getR
efCount() is static in the superclass, and static methods may not be overridden
to be nonstatic.
public class Bird |The program will compile and execute. The output will be Befo
re: 0 After: 2.
URL referring to databases use the form:|protocol:subprotocol:datasoursename
What are the legal types for whatsMyType? (Choose one.) short s = 10;whatsMyType
= !s;|There are no possible legal types.
What does the following code do? Integer i = null; if (i != null & i.intValue()
== 5) System.out.println("Value is 5");|Throws an exception.
FileOutputStream fos = new FileOutputStream("xx");|The output is i = 20.
public class A|-1
public class Xxx |An exception is thrown at line 9.
public class Q |The code compiles, and prints out >>null<<
public class Apple|An exception is thrown at line 7.
What is -50 >> 2 | -13
What is 7 % -4?|3
What is -8 % 5?|-3
What is the difference between the rules for method-call conversion and the rule
s for assignment conversion? (Choose one.)|There is no difference; the rules are
the same.
final class Aaa|On line 1, remove the final modifier. |On line 1, remove the f
inal modifier.
What is the range of values that can be assigned to a variable of type byte? (Ch
oose one.)|-2^7 through 2^7 - 1
What is the range of values that can be assigned to a variable of type short? (C
hoose one.)|-2^15 through 2^15 - 1
What is the result of attempting to compile and execute the following code fragm
ent? Assume that the code fragment is part of an application that has write perm
ission in the current working directory. Also assume that before execution, the
current working directory does not contain a file called datafile. (Choose one.)
|The code fails to compile.
The code fails to compile.|A boolean
What method of the java.io.File class can create a file on the hard drive? (Choo
se one.)|createNewFile()
public class Conditional |The output: value is 9.0
public class Xor |The output: b contains 5.
int x = 0, y = 4, z = 5;|message four
When a byte is added to a char, what is the type of the result|int
When a negative byte is cast to a long, what are the possible values of the resu
lt? (Choose one.)|Negative
When a negative long is cast to a byte, what are the possible values of the resu
lt? (Choose one.)|All the above
When a short is added to a float, what is the type of the result?|float
When comparing java.io.BufferedWriter to java.io.FileWriter, which capability ex
ists as a method in only one of the two? (Choose one.)|writing a line separator
to the stream
When does an exception's stack trace get recorded in the exception object?(Choos
e one.)|When the exception is constructed
When is it appropriate to pass a cause to an exception's constructor?(Choose one
.)|When the exception is being thrown in response to catching of a different exc
eption type
When is it appropriate to write code that constructs and throws an error? (Choos
e one.)|never
When is x & y an int? (Choose one).|Sometimes
When the user attempts to close the frame window, event in generated.|win
dow closing
When the user selects a menu item, event is generated.|Action event
When you compile a program written in the Java programming language, the compile
r converts the human-readable source file into platform- independent code that a
Java Virtual Machine can understand. What is this platform-independent code cal
led?|bytecode
Whenever a method does not want to handle exceptions using the try block, the
is used.|throws
Which are the correct statements used for getting connection object to connect t
o SQL Server database?|String url ="jdbc:odbc:data_source_name"; Connection con
= DriverManager.getConnection (url, user", "password");
Which class and static method can you use to convert an array to a List? (Choose
one.)|Arrays.asList
Which is four-step approach to help you organize your GUI thinking. (Choose one.
)|Identify needed components. Isolate regions of behavior. Sketch the GUI. Choos
e layout managers.
Which is the four steps are used in working with JDBC?|1)Connect to the database
2)Create a statement and execute the query 3)Look at the result set 4)Close con
nection
Which JDBC processing model that requires a JDBC driver that can communicate wi
th the particular data source being accessed?|two-tier
Which line of code tells a scanner called sc to use a single digit as a delimite
r? (Choose one.)|sc.useDelimiter("\\d");
Which Man class properly represents the relationship "Man has the best friend wh
o is a Dog"? (Choose one.)|class Man { private Dog bestFriend; }
Which methods return an enum constant s name? (Choose two.)|name() Which modifier
or modifiers should be used to denote a variable that should not be written out
as part of its class's persistent state? (Choose the shortest possible answer.)
toString()|transient
Which of the following are legal argument types for a switch statement? (Choose
three.)|byte - int - char
Which of the following are legal import statements? (Choose two.)|import java.ut
il.Vector; - import static java.util.Vector.*;
Which of the following are legal loop constructions? (Choose one.)|int j = 0; fo
r (int k=0, j+k != 10; j++,k++) { System.out.println("j=" + j + ", k=" + k); }
Which of the following are legal loop definitions? (Choose one.)|None of the abo
ve.
Which of the following are legal? (Choose three.)|for (int i=0, j=1; i<10; i++,
j++) - for (int i=0, j=1;; i++, j++) - for (String s = ""; s.length()<10; s += '
!')
Which of the following are legal? (Choose two.)|double d = 1.2d; double d = 1.2D
;
Which of the following are legal? (Choose two.)|int c = 0xabcd; int d = 0XABCD;
Which of the following are legal? (Choose two.)|char c = 0x1234; - char c = '\u1
234';
Which of the following are legal? (Choose two.)|List<String> theList = new Vecto
r<String>(); - List<String> theList = new Vector<String>();
Which of the following are methods of the java.util.SortedMap interface? (Choose
three.)|headMap - tailMap - subMap
Which of the following are methods of the java.util.SortedSet interface? (Choose
one.)|All the above
Which of the following are true? (Choose one.)|All the above
Which of the following are true? (Choose one.)|The JVM runs until there are no n
on-daemon threads.
Which of the following are true? (Choose two.)|When you declare a method to be s
ynchronized, the method - to be synchronized, you can specify the
Which of the following are true? (Choose two.)|An enum may contain public method
definitions. - An enum may contain private data.
Which of the following are true? (Choose two.)|Primitives are passed by value. -
References are passed by value.
Which of the following are true? (Choose two.)|An anonymous inner class may impl
ement at most one interface. - An anonymous inner class may extend a parent clas
s other than Object.
Which of the following are valid arguments to the DataInputStream constructor? (
Choose one.)|FileInputStream
Which of the following are valid mode strings for the RandomAccessFile construct
or? (Choose one.)|All the above
Which of the following calls may be made from a non-static synchronized method?
(Choose one.)|All the above
Which of the following classes implement java.util.List? (Choose two.)|java.util
.ArrayList - java.util.Stack
Which of the following classes implements a FIFO Queue? (Choose one.)|LinkedLis
t
Which of the following declarations are illegal? (Choose three.)|default String
s; - abstract double d; - abstract final double hyperbolicCosine();
Which of the following expressions are legal? (Choose two.) | int x = 6; if (!(x
> 3)) {} - int x = 6; x = ~x;
Which of the following expressions are legal? (Choose two.) | String x = "Hello"
; int y = 9; x += y; - String x = "Hello"; int y = 9; x = x + y;
Which of the following expressions results in a positive value in x? (Choose one
.)|int x = 1; x = x >>> 5;
Which of the following interfaces does not allow duplicate objects? (Choose one.
) |set
Which of the following interfaces does not allow duplicate objects? (Choose one.
)|Preconditions of a public method
Which of the following is NOTa valid comment:|/* comment
Which of the following is the most appropriate way to handle invalid arguments i
n a public method?|Throw java.lang.IllegalArgumentException.
Which of the following is true? (Choose one.) | None of the above
Which of the following is(are) true? (Choose one.) |All the above
Which of the following may appear on the left-hand side of an instance of operat
or?|A reference
Which of the following may appear on the right-hand side of an instance of opera
tor? (Choose two.)|A class - An interface
Which of the following may be declared final? (Choose two.) | Classes - Methods
Which of the following may be statically imported? (Choose two.)|Static method n
ames - Static field names
Which of the following may follow the static keyword? (Choose three.) | Data - M
ethods - Code blocks enclosed in curly brackets
Which of the following may legally appear as the new type (between the parenthes
es) in a cast operation? (Choose one.) |All of the others
Which of the following may not be synchronized? (Choose one.) | Classes
Which of the following may override a method whose signature is void xyz(float f
)? (Choose two.)|void xyz(float f) - public void xyz(float f)
Which of the following methods in the Thread class are deprecated? (Choose one.)
| suspend() and resume()
Which of the following operations might throw an ArithmeticException? (Choose on
e.) | None of these
Which of the following operations might throw an ArithmeticException? (Choose on
e.) | /
Which of the following operators can perform promotion on their operands? (Choos
e three.)|+ - ~
Which of the following restrictions apply to anonymous inner classes? (Choose on
e.)|They must be defined inside a code block.
Which of the following should always be caught? (Choose one.)|Checked exceptions
Which of the following signatures are valid for the main() method entry point of
an application? (Choose two.)|public static void main(String arg[]) - public st
atic void main(String[] args)
Which of the following statements about the wait() and notify() methods is true?
(Choose one.)|The thread that calls wait() goes into the monitor s pool of waitin
g threads.
Which of the following statements about threads is true? (Choose one.) |Threads
inherit their priority from their parent thread.
Which of the following statements are true? (Choose one.)|A final class may not
be extended
Which of the following statements are true? (Choose one.)|Given that Inner is a
nonstatic class declared inside a public class Outer and that appropriate constr
uctor forms are defined, an instance of Inner can be constructed like this: new
Outer().new Inner()
Which of the following statements are true? (Choose one.) | None of the above
Which of the following statements are true? (Choose two.)|StringBuilder is gener
ally faster than StringBuffer. - StringBuffer is threadsafe; StringBuilder is no
t.
Which of the following statements are true? 1)An abstract class may not have any
final methods. 2)A final class may not have any abstract methods.|Only statemen
t 2
Which of the following statements is correct? (Choose one.) |Both primitives and
object references can be both converted and cast.
Which of the following statements is true? (Choose one.) |Transient variables ar
e not serialized.
Which of the following statements is true? (Choose one.) |Object references can
be converted in both method calls and assignments, and the rules governing these
conversions are identical.
Which of the statements below are true? (Choose one.)|Unicode characters are all
16 bits.
Which of the statements below are true? (Choose one.)|None of the above
byte b = 5; 2. char c = 5 ;|line 6
class HiPri extends Thread |None of the above scenarios can be guaranteed to hap
pen in all cases.
import java.lang.Math;|Compilation fails at line 2.
String s = "FPT";|Compilation succeeds. No exception is thrown during execution.
String s1 = "abc" + "def";|Line 6 executes and line 4 does not.
class Greebo extends java.util.Vector implements Runnable |There will be a comp
iler error, because class Greebo does not correctly implement the Runnable inter
face.
int j = 2;|The output would be the text value is two followed by the text value
is three.
Which statement is true about the following method? int selfXor(int i) { return
i ^ i; }|It always returns 0.
class StaticStuff|The code compiles and execution produces the output x = 3.
class HasStatic|The program compiles and the output is x = 104.
Which statements about JDBC are NOT true? (choose 2)|JDBC is a Java database sy
stem. JDBC is a Java API for connecting to any kind of DBMS
Which two code fragments correctly create and initialize a static array of int
elements? (Choose two.)|static final int[] a = { 100,200 }; - static final int[]
a; static { a=new int[2]; a[0]=100; a[1]=200; }
Which two of the following interfaces are at the top of the hierarchies in the J
ava Collections Framework? (Choose two.)|Map - Collection
You execute the following code in an empty directory. What is the result? (Choos
e one.) 1. File f1 = new File("dirname"); 2. File f2 = new File(f1, "filename");
|No directory is created, and no file is created.
"A pet has an owner, a registration date, and a vaccination-due date. A cat is a
pet that has a flag indicating if it has been neutered, and a textual descripti
on of its markings."|public class Cat extends Pet
"A pet has an owner, a registration date, and a vaccination-due date. A cat is a
pet that has a flag indicating whether it has been neutered, and a textual desc
ription of its markings."|boolean neutered; - String markings;
public class Pass |doStuff x = 5 main x = 5
which of the following is incorrect | when an application begins running, there
is one deamon thread
public class test1|public float amethod(float x, float y){}
which of the following statements is true about two base protocols used for netw
orking:TPC and UDP|TPC is a connection-based protocol and UDP is not connec
public class Main|the program has a compile error
which method do you see to enable or disable components such as jbuttons|enable(
)
which of following methods of the java.io.file can be used to check whether a fi
le can be read or not|canread()
which statements about jdbc are not true|Jdbc is a java APi for connecting to an
y kind of DBMS - is a java database system
with respect to stops in RMI implementation | create interface - create object -
create stub- create client
the class is primary clas that has the driver information | drivermanager
select a correct statement | datainputstream, dataoutputstream are binary stream
s
select incorrect statement about remote class| it must extend java.rmi.server.un
icastremoteObject
the container can display three completely different components at different tim
es, depending perhaps on user input|cardlayout
public class Mine|No such file found, doing finally; -1
which to of the following interfaces are at the top of the hierarchies in the ja
va collections framework | collection - map
a dialog prevents user input to other windows in the application until the di
alog is closed | modal
MVC is short call of | model-view-controller
which of the followings statements is true | rows and columns ins a gridbaglayou
t can have different sizes
select the correct statement which set the layout manager of a given frame to fl
owlayoutmanager| setlayout(new flowlayout());
public class main|line 17 is never executed
which of the following statements is true| in the networking with client-server
model, the server computer has a socket ...also need
swing is part of the java foundation classes and provides a rich set of gui comp
onents |none of the others
fileoutputstream fos = new fileoutputstream("dest") | 12
public class setF extends frame|s.setbackground(color.pink)
which of the following layout manager will present components with the same size
|java.awt.gridlayour
the default type of the resultset object is | type_forward_only
public class main|line 17 throws an exception at runtime
select incorrect statement about remote class|it must extend java.rmi.server. re
moteObject
how can you change the current working directory using an instance of the file c
lass called filename|the file class does not support directly changing the curre
nt directory
in a client-server application model, which sides will initiate a connection|ser
ver
public class Mod|error at compilation: native method cannot be static
select the correct result of the expression: 5 >>> 1|2
class InOut|system.out.println(iArgs); - System.out.println(s);
which of the following methods of the java.io.File can be used to create a new f
ile|createNewFile()
Which of the following about Reader class is true|Reader has method that can rea
d a single character
which of the following is true|The >> operator carries the sign bit when shiftin
g right. The >>> zero-fills bits that have been shifted out
what is the difference between yielding and sleeping|when a task invokes its yie
ld() method, it returns to the ready state.
class base|Runtime exception
which of the followings is incorrect|when an application begins running, there i
s one deamon thread
which of the following is not an example pf a data type|public
which if the following is true| you cannot call enum's to string() method
what must a class do to implement an interface|it must provide all of the method
s in the interface and identify the interface in its implements clause
all of the numeric wrapper classes in the java.lang package are subclasses of th
e abstract class|java.lang.number
which of the following modifiers does not allow a variable to be modified its va
lue once it was initialized|final
public static void main|the program will run and output only "fliton"
RMI applications often often comprise two separate programs, a server and a clie
nt and they|can run in two separate machine
abstract class minebase|Error mine must be declared abstract
which of the following is true about Wrapped classes| Wrapped classes are classe
s that allow primitive types to be accessed as objects
if(check4Biz(storeNum)!= null){}|boolean - String
for a class defined inside a method, what rule governs access to the variables o
f the enclosing method|the class can only access final variables
select the correct statement which set the layout manager of a given frame to fl
owlayoutmanager | setLayout(new Flowlayout());
select the correct syntax for throwing an exception when declaring a method | [M
odifier] {return type] Indentifier (Parameters) throws TypeofException
in RMI implementations, all methods, declared in the remote interface, must thro
w the exception|java.rmi.RemoteException
public class Funcs extends java.lang.math|The line 10 causes compile-time error
which of the following statements is true about a variable created with the stat
ic modifier|A static variable created in a method will keep the same value betwe
en calls
try {|ac
what will happen if you try to compile and run the following code | 2
line.point p = new line.point();| true
the default type of the resultset object is| TYPE_FORWARD_ONLY
base(){} base (intj,int k){}| true
foo(count); | 1
suppose the declared type of x is a class| when the type of x is object
A method in an interface can access class level | true
double d = 1.2d|true
Access the variables only via synchronized methods | true
the swing's list + the swing's label| true
which of the following operations might throw an arithmetic exception| %
under no circumstances + adding more classes| true
a protected method may only be accessed by classes of the same | true
vector does not allow duplicate elements | true
datainputstream | fileinputstream
the program cause errors when it is compiled | true
tcp is a connection-based protocol | true
to check whether the file denoted by the abstract | true
what is the output when you try to compile and run the | EQUAL
we don't need any method because elements in vector are automatically sorted | t
rue
setlayout(new flowlayout());| true
for (float f:salaries)| true
a runtime error indicating that no run method |true
if(s.equalIgnoreCase(s2))| true
output one one two two | true
String x = *Hello*. int y = 9;x= x+ y | true
the compiler will compalin that the base class is not declared as abstract | tru
e
No compiler error and no exception | class A
you can not call an enum's to string | true
creatnewfile()| true
given a string constructed by calling s = new String("xyzzy") | none of the othe
r
b=m; | class base{}
cannot call to a static synchonized method | true
How can you force garbage collection of an object | garbage collection cannot be
force
char c = \u1234| true
boderlayout is the default layout manager | true
if(s.equalsIgnoreCase(s2)) | true
int x = 6; x =~x | true
What is the return type of the instanceof operator? | A boolean
Wrapper classes are: Boolean, Char, Byte, Short, Integer, Long, Float and Double
| true
The GridBagLayout managet is the default manager for JFame | true
When you construct an instance of File, the file will bot be created even if the
corresponding file does not exist on the | true
public interface B instanceOf A {} | true
A for statement can loop infinitely, for example: for(;;); | true
a # b; a == c | true
How many strings, specified by the above code, are stored in the memory of the p
rogram? | 2
What is the difference between a TextArea and a TextField? | A TextArea can hand
le multiple lines of text
You have been given a design document for a veterinary registration system for i
mplementation in Java. It states: | String markings; boolean neutered
The default type of the ResultSet object is...| TYPE_FORWARD_ONLY
Suppose the declared type of x is a class, and the declared type of is an interf
ace. When is the assignment x=y: legal? | When the type of x is Object
Which of the following statements is INCORRECT? | A method in a interface can ac
cess class level
Which of the following is legal? | double d =1.2d
How do you prevent shared data from being corrupted in a multithreaded environme
nt? | Access the variables only via synchronized
Sellect correct statement | 1.3
Which of the following operations might throw an ArithmeticException?| %
Select the most correct statement | A protected method may only be accessed by c
lasses of the same package or by subclasses of he class in which itt is declared
Which of the following statements is incorrect? | Vector does not allow duplicat
e elements
What is 7 % -4? | 3
A signed data type has an equal number of non-zero positive and negative values
available | false
Whih of the following statements is correct ? | Both primitives and object refer
ences can be both converted and cast
Which of the following statements is true about two base protocols used for netw
orking: TCP and UDP | TCP is a connection-based protocol and UDP is not connecti
on-based protocol
Which of the statements below are true ? | To check whether the file denoted by
the abstract pathname is a directory or not, call the isDirectory() method of th
e File class
Which of the following methods of the Collections class can be used to find the
largest value in a Vector? | We don't need any method because elements in Vector
are automatically sorted. Therefore, the first element contains the macimum val
ue
Select the correct statement which set the layout manager of a given frame to Fl
owLayoutManager | setLayout(new FlowLayout();
Suppose salaries is an array containing floats. Which of the following are valid
loop control statements for processing each element of salaries? | for (float f
:salaries)
Whenever a method does not want to handle exceptions using try block, the______i
s used. | throws
Which of the following is true? | You cannot call an enum's toString() method
Which is the four steps are used in working with JDBC? |1Create a statement and
ecevute the query (2) Create the connection (3) Look at the result set (4) Close
connection
Which of the following method of the java.io.File can be used to create a new fi
le? | createNewFile()
Given a string constructed by calling s = new String("xyzzy"), which of the call
s modifies the string? | None of the others
Which of the following statements in INCORRECT about a non-static synchronized m
ethod? | It cannot call to a static synchronized method of the current class
Which of the following is INCORRECT? | char c=\u1234;
In RMI implementations, all methods, declared in the remote interface, must thro
w the...exception | java.rmi.RemoteException
What method of the java.io.File class can create a file on the hard drive? | cre
ateNewFile()
Which of the following statement is true? | BorderLayout is the default layout m
anager for every JFrame
A_____dialog prevents user input to other windows in the application until the d
ialof is closed. | Modal
How do you prevent shared data from being corrupted in a multithreaded environme
nt? | Access the variables only via synchronized methods
When a user selects a menu item, ______ is generated | Action event
Which of the following operators can perform promotion on their operands? | + -
Which line contains only legal statements? | int x=6; x=~x;
Which Man class property represents the relationship "Man has the best friend wh
o is a Dog"?| class Man { private BestFriend dog;}
Select the most correct statement | A thread is in the ready state after it has
been created and started
What is the return type of the instanceof operator? | A boolean
Which of the following is true about Wrapped classes? | Wrapper classes are: Boo
lean, Char, Byte, Short, Integer, Long, Float and Double
What is the range of values that cacn be assigned to a variable of type short? |
-2^15 through 2^15 -1
When is it appropriate to pass a cause to an exception's constructor? | When the
exception is being thrown in response to catching of a different exception type
Which of the statement below is true? | When yuo construct an instance of File,
the file will not be created even if the corresponding file does not exist on th
e local system
Which of the following may follow the static keyword? (Select two) | Methods and
Non-inner class definitions
Which of the following statements is true? | Constructors are not inherited
Which of the following statements is true? | A for statement can loop infinitely
, for example: for(;;);
Select INCORRECT statement about deserialize. | We use readObject() method of Ob
jectOutputStream class to deserialize
A(n)_____object is uses to obtain a Connection to a Database | DriverManager
What is the difference between a TextArea and A TextField? | A TextArea can hand
le multipe lines of text