Java
Java
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
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
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
What is the range of data type short in Java?|-32768 to 32767
What is the range of data type byte in Java? |-128 to 127
Which of the following are legal lines of Java code?
int w = (int)888.8;2. byte x = (byte)100L;3. long y = (byte)100;4. byte z = (by
te)100L; | All statements are correct.
An expression involving byte, int, and literal numbers is promoted to which of t
hese? | int
Which of these literals can be contained in a data type float variable? | 3.4e038
Which data type value is returned by all transcendental math functions? |double
What is the output of this program? class average {public static void main(Str
ing args[]){double num[] = {5.5, 10.1, 11, 12.8, 56.9, 2.5};double result;result
= 0;for (int i = 0; i < 6; ++i) result = result + num[i];System.out.print(resul
t/6);} } |16.46666666666667