Which the following statement is true about PriorityQueue a An ordered sequence that allows efficient insertions and removal at any location b A data structure that stores key/value asso
Trang 11 Threads can be in one of four states:
a) New, Running, Sleeping, Dead
b) New, Runnable, Blocked, Dead
c) Start, Running, Sleeping, Stop
d) Start, Blocked, Sleeping, Stop
2 To find out whether a thread is currently alive, use the method
4 With JDK 5, two mechanisms for protecting a code block from concurrent access, there are:
a) Using the synchronized and unsynchrinized keyword
b) Using the EntrantLock and ReentrantLock class
c) Using the synchronized keyword and EntrantLock class
d) Using the synchronized keyword and ReentrantLock class
5 Blocking Queue Operation: poll (removes and returns the head element) returns _if the queue was empty
a) false
b) null
c) true
d) None of above
6 Which the following statement is true about Runnable and Callable interfaces
a) A Callable is similar to a Runnable, but it returns a value
b) Runnable is similar to Callable
c) Runnable is similar to Future
d) Callable is similar to Future
7 Which the following statement is true about HashSet
a) A sorted set
b) An unordered collection that rejects duplicates
c) A set of enumerated type values
d) An ordered sequence that allows efficient insertions and removal at any location
8 Which the following statement is true about PriorityQueue
a) An ordered sequence that allows efficient insertions and removal at any location
b) A data structure that stores key/value associations
c) A collection that allows efficient removal of the smallest element
d) A map that remembers the order in which entries were added
9 See the following code
List<String> staff = new <String>();
Trang 2String first = iter.next();
String second = iter.next();
iter.remove();
Which the following statement is correct?
a) Adds three elements and and then removes all of them
b) Adds three elements and and then removes the second one
c) Adds three elements and and then removes the first one
d) Adds three elements and and then removes the last one
10 List<String> staff = new LinkedList<String>();
a) Skips past the two first elements in the linked list and adds "Juliet" before the third element
b) Adds "Juliet" as the first element of the linked list
c) Skips past the third element in the linked list and adds "Juliet" before the fourth element
d) Skips past the first element in the linked list and adds "Juliet" before the second element
11 What is the main different between ArrayList and Vector collection?
a) All methods of the Vector class are synchronized
b) All methods of the ArrayList class are synchronized
c) All of a, b are correct
d) All of a, b aren't correct
12 A hash table is an array of linked lists Each list is called a _
14 See the following code
SortedSet<String> sorter = new TreeSet<String>(); // TreeSet implements SortedSet
Trang 3a) Inserts four strings and then visit the first element.
b) Inserts four strings and then visit all elements have added.
c) Inserts four strings and then visit the second element
d) Inserts three strings and then visit all elements have added
15 The tree set assumes that you insert elements that implement the Comparable interface
a) The call a.compareTo(b) must return true if a and b are equal
b) The call a.compareTo(b) must return false if a and b are equal
c) The call a.compareTo(b) must return 0 if a and b are equal, a negative integer if a comes before b in the sort order, and a positive integer if a comes after b.
d) The call a.compareTo(b) must return 0 if a and b are equal, a positive integer if a comes before b
in the sort order, and a negative integer if a comes after b
16 The Java library supplies two general-purpose implementations for maps: HashMap and TreeMap Both classes implement the _ interface
a) UnsortedMap
b) SortedMap
c) Map
d) MapInterface
17 putAll(Map<? extends K, ? extends V> entries)
a) Remove all entries from the specified map to this map
b) Adds all entries from the specified map to this map.
c) None of above are correct
d) All of above are correct
18 Which the following statement is correct?
a) The EnumSet is an efficient set implementation with elements that belong to user-defined type
b) The EnumSet is an efficient set implementation with elements that belong to an enumerated type.
c) The EnumSet is an efficient set implementation with elements that belong to a specific type.d) The EnumSet isn't an efficient set implementation with elements that belong to an enumerated type
19 Which the following statements are correct about the collections framework
a) The collection framework defines a number of interfaces and abstract classes for implementors of collections
b) A framework is a set of classes that form the basis for building advanced functionality A framework contains superclasses with useful functionality, policies, and mechanisms.
c) A framework is an interface using for predefining methods
Trang 421 The static method in the Collections class can turn any map into a Map with synchronized access methods.
a) setSynchronizedMap( )
b) getsynchronizedMap( )
c) setSynchronized( )
d) synchronizedMap( )
22 See the following code
if (a.length == 0) throw new NoSuchElementException();
T largest = a[0];
for (int i = 1; i < a.length; i++)
if (largest.compareTo(a[i]) < 0)
largest = a[i];
a) These lines used to find the smallest element of an array
b) These lines used to find the specify element of an array
c) These lines used to find the largest element of an array.
d) These lines used to replace the largest element of an array
23 The Collections class has an algorithm _ that does the opposite of sortingit randomly permutes the order of the elements in a list You supply the list to be shuffled and a random number generator
a) Collections.shuffle( )
b) Collections.short( )
c) Collections.shuffleAll( )
d) Collections.binarySearch( )
24 A property set is a map structure of a very special type
a) The keys and values are numbers The table can be saved to a file and loaded from a file A
secondary table for defaults is used
b) The keys are strings and values are numbers The table can be saved to a file and loaded from a file
A secondary table for defaults is used
c) The keys and values are strings The table can be saved to a file and loaded from a file A
secondary table for defaults is used.
d) The keys and values are strings The table cannot be saved to a file and loaded from a file A
secondary table for defaults is used
25 The class gives you a convenient interface for reading, setting, or resetting individual bits a) ByteSet
b) BitSetCollections
c) BitSet
d) ByteCollections
26 The following statement is using for what?
ServerSocket s = new ServerSocket(1609);
a) Establishes a server that monitors port 1609
b) Establishes a client that monitors port 1609
c) Establishes a server that monitors port 8180
d) Establishes a client that monitors port 8180
Trang 527 See the following commands:
ServerSocket s = new ServerSocket(8189);
Socket incoming = s.accept();
a) The second line tells the program to accept all connections from clients
b) The second line tells the program to deny all client connects to 8180 port
c) The second line tells the program to wait indefinitely until a client connects to 8189 port
d) The second line tells the program not to wait indefinitely until a client connects to 8189 port
28 Open a socket to your host
Socket s = new Socket("mail.yourserver.com", 25);
PrintWriter out = new PrintWriter(s.getOutputStream());
a) Port 25 is served Simple Mail Transfer Protocol
31 See the following commands:
Socket s = new Socket( .);
s.setSoTimeout(10000);
a) The second line set time out after 100 seconds
b) The second line set time out after 1 second
c) The second line set time out after 10 seconds
d) The second line set time out after 1000 seconds
32 To interrupt a socket operation, you use a , a feature of the java.nio package
a) SocketChannel
b) SocketOperation
c) SocketInterrupted
d) SocketGetInterrupted
Trang 633 You can close the output stream of a socket, thereby indicating to the server the end of the request data, but keep the input stream open so that you can read the response The _ overcomes this problem
public class InetAddressTest {
public static void main(String[] args) {
try {
if (args.length > 0) {
String host = args[0];
InetAddress[] addresses = InetAddress.getAllByName(host);
for (InetAddress a : addresses)
b) Supply a host name as command-line argument to see the address of the local host.
c) Supply a host name as command-line argument to see the address of the 192.168.1.1 host
d) Supply the address of the local host
35.JDBC drivers are classified into the types
Trang 737 The class selects database drivers and creates a new database connection.
39 Method clearParameters() of PreparedStatement is using for
a) Clears all current parameters in the prepared statement.
b) Clears current parameters in the prepared statement
c) Fill all current parameters in the prepared statement
d) Fill current parameters in the prepared statement
40.To obtain scrollable result sets from your queries, you must obtain a different Statement object with the method
Statement stat = conn.createStatement(type, concurrency);
if type=yTYPE_SCROLL_INSENSITIVE,
a) The result set is not scrollable
b) The result set is scrollable but not sensitive to database changes.
c) The result set is scrollable and sensitive to database changes
a) The result set can be used to delete the database
b) The result set can be used to update the database.
c) The result set cannot be used to update the database
d) The result set cannot be used to execute the database
42 JDBC can give you additional information about the structure of a database and its tables To find out more about the database, you request an object of type from the database connection
a) ResultSetMetaData
b) RowSetMetaData
c) DatabaseMetaData
d) TableSetMetaData
Trang 843 The method of java.sql.ResultSetMetaData returns the number of columns in the current ResultSet object.
46 When a JDBC application is deployed in an enterprise environment, the management of database
connections is integrated with the _
a) Java 2 Enterprise Edition (J2EE)
b) Java Naming and Directory Interface (JNDI)
c) Remote Methods Invocation (RMI)
d) None of above
47 A database connection is in autocommit mode, and each SQL command is committed to the database as soon as it is executed Once a command is committed, you cannot roll it back To turn off autocommit mode with the command
a) Statement stat = conn.preparedStatement();
b) Statement stat = conn.requiredStatement();
c) Statement stat = conn.createStatement();
Trang 9d) Statement stat = conn.getStatement();
49 The process of encoding the parameters is called _ The purpose of is to convert the parameters into a format suitable for transport from one virtual machine to another
54 The java.rmi.activation.Activatable has exportObject method The prototype od this method is
a) Remote exportObject(Remote obj, ActivationID id, int port)
b) RemoteObject exportObject(Remote obj, ActivationID id, int port)
c) static Remote exportObject(Remote obj, ActivationID id, int port)
d) static RemoteObject exportObject(Remote obj, ActivationID id, int port)
55 A bean is a _ based on Sun's JavaBeans specification that can be manipulated visually in a builder tool
a) recompile software component
b) reusable tool
c) reusable software component
d) reusable object
Trang 1056 To make the JAR file, follow these steps:
1 Edit the manifest file
2 Gather all needed class files in a directory
3 Run the jar tool as follows:
a) jar cvfm JarFile ManifestFile ClassFiles
b) jar cvfm ManifestFile ClassFiles JarFile
c) jar cvfm ManifestFile JarFile ClassFiles
d) jar cvfm ClassFiles JarFile ManifestFile
57 Bean Property Types include:
a) Simple, Indexed, Constrained Properties
b) Simple, Bound, Constrained Properties
c) Simple, Indexed, Bound, Constrained Properties
d) Indexed, Bound, Constrained Properties
58 A is constrained by the fact that any listener can "veto" proposed changes, forcing it to revert to the old setting
Trang 1162 All exceptions fall into either of two categories:
a) checked and unchecked
b) RunTime and CompileTime
c) good and badunchecked
d) Exception and Errored
63 An object of the Hashtable class can store and retrieve object references based on associated "key" objects Which interface does Hashtable implement?
a) SortedMap
b) SortedSet
c) Map
d) List
64 How are computers on the Internet located?
a) By their registration number
b) By their Internet ID number
c) By their IP address
d) By their locator chip
65 How can the priority of a thread be set?
Select the one correct answer
a) By using the setPriority() method in the class Thread.
b) None of the other answers
c) By passing the priority as a parameter to the constructor of the thread
d) Both of the other answers
66 How can you determine which component has the focus?
a) You poll through all components in a loop until this is true: getFocus(componentName)
b) You use getFocus() from the top window
c) You poll through all components in a loop with isActive
d) You poll through all windows in a loop until you get the component with focus with
getFocusOwner()
67 How do Swing menus differ from AWT menus?
a) Swing menus are round
b) Swing menus are components
c) Swing menus are implemented in separate windows
d) None of the other answers
68 How do you create a multiple selection mode JComboBox?
a) Use a JList for multiple selection because JComboBox is only single selection.
b) With: setMode(MULTIPLE_SELECTION)
c) With: setSelectionMode(true)
d) With: setMode(true)
69 How do you group a set of option buttons with a border and title?
a) You add all the buttons to a JWindow
b) You add the buttons in various ways, but you group them programmaticall
Trang 12c) You add each button to its own JFrame and then add all those JFrames to a window
d) You place the option buttons you want to group in a JPanel, and then you add a border to the JPanel.
70 How do you properly size a component immediately after creating it?
a) How do you properly size a component immediately after creating it?
b) With: doLayout()
c) With: addNotify().
d) With: setComponentOrientation()
71 How does a *.java file differ from a *.class file?
a) A *.java file is bytecode
b) A *.class file is source code
c) A * class file is a compiled *.java file
d) A *.java file is a compiled *.class file
72 How does the set collection deal with duplicate elements?
a) An exception is thrown if you attempt to add an element with a duplicate value
b) The add method returns false if you attempt to add an element with a duplicate value
c) Duplicate values will cause an error at compile time Question Help
d) A set may contain elements that return duplicate values from a call to the equals method
73 How is the forName() method of the Class class used with JDBC?
a) To establish a database connection
b) To load a JDBC driver
c) To execute a SQL statementresses
d) To load a result set
74 In Java, which statement will establish a new TCP/IP connection to a server, java.sun.com?
a) Socket s = new Socket("java.sun.com", 80);
b) ServerSocket server = new ServerSocket(8000);
c) Connection s = new Connection("java.sun.com", 80);
76 InputStream and OutputSteam are
a) The top-level abstract classes defined in the java.io package, from which all other stream classes inherit
b) The top-level abstract classes defined in the java.io package, from which all other byte stream classes inherit
c) Interfaces that define methods that can be used to read and write bytes