Bài tập trắc nghiệm có đáp án

25 1.8K 0
Bài tập trắc nghiệm có đáp án

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

1. 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 a) isActive() b) isAlive() c) isEnabled() d) isStillAlive() 3. Turn a thread into a daemon thread by calling a) t.getDaemon(true); b) t.setThreadDaemon(true); c) t.setDaemon(true); d) t.setThreadPriority 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>(); staff.add("Amy"); staff.add("Bob"); staff.add("Carl"); Iterator iter = staff.iterator(); String 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>(); staff.add("Amy"); staff.add("Bob"); staff.add("Carl"); ListIterator<String> iter = staff.listIterator(); iter.next(); iter.add("Juliet"); 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 _______________ a) set b) recordset c) bucket d) batch 13. If an object has hash code 76268 and there are 128 buckets, then the object is placed in bucket ________ a) 109 b) 110 c) 108 d) 111 14. See the following code SortedSet<String> sorter = new TreeSet<String>(); // TreeSet implements SortedSet sorter.add("Bob"); sorter.add("Amy"); sorter.add("Carl"); sorter.add("John"); for (String s : sorter) System.println(s); a) 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 d) None of above 20. The _____________ method is declared to have a variable number of arguments. Instead of passing an array, you can also pass individual elements a) asAlist( ) b) list( ) c) asList( ) d) addList( ) 21. 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. 27. 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 b) Port 25 is served FTP c) Port 25 is served HTTP d) Port 25 is served SSH 29. The URL and _____________ classes encapsulate much of the complexity of retrieving information from a remote site. a) URLDataConnection b) URLConnection c) URLConnectionData d) URLCollections 30. With URLConnection, the method getRequestProperties() returns a map of request properties. All values for the same key are placed in a list. Which the following statement is correct? a) Map<String,List<String>> getRequestProperties() b) Map<Integer,List<String>> getRequestProperties() c) Map<Integer,List<Integer>> getRequestProperties() d) Map<Double,List<String>> getRequestProperties() 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 33. 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. a) half-stop b) half-connection c) half-close d) half-diconnection 34. See the folowing statements import java.net.*; 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) System.out.println(a); } else { InetAddress localHostAddress = InetAddress.getLocalHost(); System.out.println(localHostAddress); } } catch (Exception e) { e.printStackTrace(); } } } a) Supply a host name as command-line argument, or run without command-line arguments to see the address of the local host. 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 a) 1 b) 2 c) 3 d) 4 36. The general syntax of database URL is a) jdbc:odbc:subprotocol:other stuff b) jdbc:subprotocol:odbc:other stuff c) jdbc:subprotocol:odbc d) jdbc:subprotocol:other stuff 37. The ____________ class selects database drivers and creates a new database connection. a) DriverManager b) DriverConnectionManager c) Connection Manager d) ManagementConnection 38. Prepare a query with a host variable and use it many times, each time filling in a different string for the variable. That technique benefits performance. Using __________ class for this purpose. a) Statement b) PreparedStatement c) RequiredStatement d) PrepareQueryStatement 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. d) None of above. 41.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 concurrency=CONCUR_UPDATABLE 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 43. The method __________ of java.sql.ResultSetMetaData returns the number of columns in the current ResultSet object. a) getColumnLabel(int column) b) getColumnDisplaySize(int column) c) getColumnCount() d) getColumnName(int column) 44. A __________ is a cached row set that can be saved to an XML file. a) WebRowSet b) CachedRowSet c) FilteredRowSet d) JoinRowSet 45. The method ___________ of javax.sql.rowset.CachedRowSet populates this cached row set with the data from the given result set. a) setCommand(String command) b) populate(ResultSet result) c) setURL(String url) d) acceptChanges() 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) Connection conn = conn.setAutoCommit(false); b) Connection conn = conn.setAutoCommit(true); c) Connection conn = conn.setAutoCommit(); d) Connection conn = conn.setAutoCommit(on); 48. To create statement objects, use the Connection object (conn) that you obtained from the call to DriverManager.getConnection. a) Statement stat = conn.preparedStatement(); b) Statement stat = conn.requiredStatement(); c) Statement stat = conn.createStatement(); d) 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. a) parameter encoding b) parameter marshalling c) parameter decoding d) parameter analyzing 50. RMI URLs start with _________ and are followed by a server, an optional port number, another slash, and the name of the remote object. a) http:// b) ftp:// c) smtp:// d) rmi:// 51. The RMISecurityManager __________ all code in the program from establishing network connections. a) restricts b) gets c) receives d) accesses 52. RMI uses the _________ mechanism to send objects across a network connection. a) non-serialization b) serialization c) comparation d) non-comparation 53. The __________ mechanism lets you delay the object construction so that a server object is only constructed when at least one client invokes a remote method on it. a) deactivation b) start c) activation d) stop 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 56. 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. a) constrained property b) indexed property c) bound property d) simple property 59. __________ tell interested listeners that their value has changed. a) Indexed properties b) Simple properties c) Bound properties d) Constrained properties 60. You can define an object that implements the ____________ interface to describe your bean. a) BeanInfo b) BeanInfomation c) BeanMetaData d) BeanMetaInfo 61. For a system consisting of exclusively Java objects, which distributed technology would be most appropriate for communication? a) CORBA b) JavaBean c) JNDI d) RMI . 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,. InetAddress.getLocalHost(); System.out.println(localHostAddress); } } catch (Exception e) { e.printStackTrace(); } } } a) Supply a host name as command-line argument, or run without command-line arguments. 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

Ngày đăng: 13/05/2014, 11:20

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan