Final: Java Chapters 30, 31, and 32

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

33.6 To connect to a server running on the same machine with the client, which of the following can be used for the hostname? A. "localhost" B. "127.0.0.1" C. InetAddress.getLocalHost(), D. "127.127.127.1".

A. "localhost" B. "127.0.0.1" C. InetAddress.getLocalHost(),

32.28 Which of the following statements are true? A. A condition is associated with a lock. B. To invoke methods on a condition, the lock must be obtained first. C. Once you invoke the await method on a condition, the lock is automatically released. Once the condition is right, the thread re-acquires the lock and continues executing. D. The signal method on a condition causes the lock for the condition to be released.

A. A condition is associated with a lock. B. To invoke methods on a condition, the lock must be obtained first. C. Once you invoke the await method on a condition, the lock is automatically released. Once the condition is right, the thread re-acquires the lock and continues executing.

34.6 ________ is an attribute or a set of attributes that uniquely identifies the relation. A. A superkey B. A key C. A candidate key D. A primary key

A. A superkey

32.21 Which of the following statements are true? A. A synchronized instance method acquires a lock on the object for which the method was invoked. B. A synchronized instance method acquires a lock on the class of the object for which the method was invoked. C. A synchronized statement can be used to acquire a lock on any object, not just this object, when executing a block of the code in a method. D. A synchronized statement is placed inside a synchronized block.

A. A synchronized instance method acquires a lock on the object for which the method was invoked. B. A synchronized instance method acquires a lock on the class of the object for which the method was invoked. C. A synchronized statement can be used to acquire a lock on any object, not just this object, when executing a block of the code in a method. D. A synchronized statement is placed inside a synchronized block.

32.31 You can create a blocking queue using _____________. A. ArrayBlockingQueue B. LinkedBlockingQueue C. PriorityBlockingQueue D. PriorityQueue

A. ArrayBlockingQueue B. LinkedBlockingQueue C. PriorityBlockingQueue

34.25 Which of the following statements are true? A. CallableStatement is a subinterface of PreparedStatement B. CallableStatement is for SQL query statements only. You cannot create a CallableStatement for SQL update statements. C. CallableStatement is more efficient than PreparedStatement. D. CallableStatement is for executing predefined functions and procedures.

A. CallableStatement is a subinterface of PreparedStatement D. CallableStatement is for executing predefined functions and procedures.

34.20 Which of the following are interfaces? A. Connection B. Statement C. ResultSet D. DriverManager

A. Connection B. Statement C. ResultSet

34.4 _________ specify the permissible values for an attribute. A. Domain constraints B. Primary key constraints C. Foreign key constraints D. intra-relational constraints E. inter-relational constraints

A. Domain constraints

34.5 ________ are known as intra-relational constraints, meaning that a constraint involves only one relation. A. Domain constraints B. Primary key constraints C. Foreign key constraints

A. Domain constraints B. Primary key constraints

32.19 How do you create a cached thread pool? A. ExecutorService executor = Executors.newCachedThreadPool(); B. ExecutorService executor = Executors.newCachedThreadPool(1); C. ExecutorService executor = Executors.newCachedThreadPool(2); D. ExecutorService executor = Executors.newCachedThreadPool(3);

A. ExecutorService executor = Executors.newCachedThreadPool();

34.22 Which of the following statements are true? A. PreparedStatement is a subinterface of Statement B. PreparedStatement is for SQL query statements only. You cannot create a PreparedStatement for SQL update statements. C. PreparedStatement is efficient for repeated executions. D. The parameters in a prepared statement are denoted using the ? sign.

A. PreparedStatement is a subinterface of Statement C. PreparedStatement is efficient for repeated executions. D. The parameters in a prepared statement are denoted using the ? sign.

32.33 Which of the following statements are true? A. Semaphores can be used to restrict the number of threads that access a shared resource. B. Before accessing the resource, a thread must acquire a permit from the semaphore. C. After finishing with the resource, the thread must return the permit back to the semaphore. D. You can create a Semaphore with a specified number of permits.

A. Semaphores can be used to restrict the number of threads that access a shared resource. B. Before accessing the resource, a thread must acquire a permit from the semaphore. C. After finishing with the resource, the thread must return the permit back to the semaphore. D. You can create a Semaphore with a specified number of permits.

33.4 The client requests a connection to a server using the following statement: A. Socket s = new Socket(ServerName, port); B. Socket s = serverSocket.accept(); C. Socket s = serverSocket.getSocket(); D. Socket s = new Socket(ServerName);

A. Socket s = new Socket(ServerName, port);

34.1 In a relational data model, _________ defines the representation of the data. A. Structure B. Integrity C. Language D. SQL

A. Structure

32.4 Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Test t = new Test(); t.start(); } public void run() { } } A. The program does not compile because the start() method is not defined in the Test class. B. The program compiles, but it does not run because the start() method is not defined. C. The program compiles, but it does not run because the run() method is not implemented. D. The program compiles and runs fine.

A. The program does not compile because the start() method is not defined in the Test class.

32.1 Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Thread t = new Thread(this); t.start(); } public void run() { System.out.println("test"); } } A. The program does not compile because this cannot be referenced in a static method. B. The program compiles fine, but it does not print anything because t does not invoke the run() method. C. The program compiles and runs fine and displays test on the console. D. None of the above.

A. The program does not compile because this cannot be referenced in a static method.

34.8 To retrieve all courses with more than 3 credit hours, you write select * from Course where numOfCredits > 3; Is this statement correct? A. Yes B. No

A. Yes

32.16 Which of the following statements are true? A. You can use a timer or a thread to control animation. B. A timer is a source component that fires an ActionEvent at a 'fixed rate.' C. The timer and event-handling run on the same event dispatcher thread. If it takes a long time to handle the event, the actual delay time between two events will be longer than the requested delay time. D. In general, threads are more reliable and responsive than timers.

A. You can use a timer or a thread to control animation. B. A timer is a source component that fires an ActionEvent at a 'fixed rate.' C. The timer and event-handling run on the same event dispatcher thread. If it takes a long time to handle the event, the actual delay time between two events will be longer than the requested delay time. D. In general, threads are more reliable and responsive than timers.

34.17 Which of the following statements are true? A. You may load multiple JDBC drivers in a program. B. You may create multiple connections to a database. C. You may create multiple statements from one connection. D. You can send queries and update statements through a Statement object.

A. You may load multiple JDBC drivers in a program. B. You may create multiple connections to a database. C. You may create multiple statements from one connection. D. You can send queries and update statements through a Statement object.

34.28 Database meta data are retrieved through ____________. A. a Connection object B. a Statement object C. a ResultSet Object D. a PreparedStatement object

A. a Connection object

32.32 Which of the following statements are true? A. a blocking queue has a capacity. B. A blocking queue causes a thread to block when you try to add an element to a full queue. C. A blocking queue causes a thread to block when you try to remove an element from an empty queue. D. The BlockingQueue interface is the base interface for all concrete blocking queue classes. E. The BlockingQueue interface provides the synchronized put and take methods for adding an element to the head of the queue and for removing an element from the tail of the queue,

A. a blocking queue has a capacity. B. A blocking queue causes a thread to block when you try to add an element to a full queue. C. A blocking queue causes a thread to block when you try to remove an element from an empty queue. D. The BlockingQueue interface is the base interface for all concrete blocking queue classes. E. The BlockingQueue interface provides the synchronized put and take methods for adding an element to the head of the queue and for removing an element from the tail of the queue,

32.2 What is the output of the following code? // Test.java: Define threads using the Thread class public class Test { /** Main method */ public static void main(String[] args) { new Test(); } public Test() { // Create threads PrintChar printA = new PrintChar('a', 4); PrintChar printB = new PrintChar('b', 4); // Start threads printA.run(); printB.run(); } class PrintChar implements Runnable { private char charToPrint; // The character to print private int times; // The times to repeat /** Construct a thread with specified character and number of times to print the character */ public PrintChar(char c, int t) { charToPrint = c; times = t; } /** Override the run() method to tell the system what the thread will do */ public void run() { for (int i = 0; i < times; i++) System.out.print(charToPrint); } } } A. aaaaabbbbb B. bbbbbaaaaa C. character a and b are randomly printed D. ababababab

A. aaaaabbbbb

32.26 Which method on a condition should you invoke to causes the current thread to wait until the condition is signaled? A. condition.await(); B. condition.wait(); C. condition.waiting(); D. condition.waited();

A. condition.await();

34.29 What information may be obtained from a DatabaseMetaData object? A. database URL and product name B. JDBC driver name and version C. maximum number of connections to the database D. maximum table name length and maximum number of columns in a table

A. database URL and product name B. JDBC driver name and version C. maximum number of connections to the database D. maximum table name length and maximum number of columns in a table

33.1 When creating a server on a port that is already in use, __________. A. java.net.BindException occurs B. the server is created with no problems C. the server is blocked until the port is available D. the server encounters a fatal error and must be terminated

A. java.net.BindException occurs

32.9 You can use the _________ method to temporarily release time for other threads. A. sleep(long milliseconds) B. yield() C. stop() D. suspend()

A. sleep(long milliseconds) B. yield()

33.2 When creating a client on a server port that is already in use, __________. A. the client can connect to the server regardless of whether the port is in use B. java.net.BindException occurs C. the client is blocked until the port is available D. the client encounters a fatal error and must be terminated

A. the client can connect to the server regardless of whether the port is in use

32.24 You should always invoke the unlock method in the finally clause. A. true B. false

A. true

34.9 Which of the following statements loads the JDBC-ODBC driver? A. Class.forName(sun.jdbc.odbc.JdbcOdbcDriver) B. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver") C. Class.loadClass(sun.jdbc.odbc.JdbcOdbcDriver) D. Class.loadClass("sun.jdbc.odbc.JdbcOdbcDriver")

B. Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")

34.11 Invoking Class.forName method may throw ___________. A. RuntimeException B. ClassNotFoundException C. IOException D. SQLException

B. ClassNotFoundException

32.25 How do you create a condition on a lock? A. Condition condition = lock.getCondition(); B. Condition condition = lock.newCondition(); C. Condition condition = Lock.newCondition(); D. Condition condition = Lock.getCondition();

B. Condition condition = lock.newCondition();

34.19 Suppose that your program accesses MySQL or Oracle database. Which of the following statements are true? A. If the driver for MySQL and Oracle are not in the classpath, the program will have a syntax error. B. If the driver for MySQL and Oracle are not in the classpath, the program will have a runtime error, indicating that the driver class cannot be loaded. C. If the database is not available, the program will have a syntax error. D. If the database is not available, the program will have a runtime error, when attempting to create a Connection object.

B. If the driver for MySQL and Oracle are not in the classpath, the program will have a runtime error, indicating that the driver class cannot be loaded. D. If the database is not available, the program will have a runtime error, when attempting to create a Connection object.

33.7 To create an InputStream on a socket s, you use __________. A. InputStream in = new InputStream(s); B. InputStream in = s.getInputStream(); C. InputStream in = s.obtainInputStream(); D. InputStream in = s.getStream();

B. InputStream in = s.getInputStream();

34.2 In a relational data model, _________ imposes constraints on the data. A. Structure B. Integrity C. Language D. SQL

B. Integrity

32.22 Which of the following are correct statements to create a Lock? A. Lock lock = new Lock(); B. Lock lock = new ReentrantLock(); C. Lock lock = new ReentrantLock(true); D. Lock lock = new ReentrantLock(false);

B. Lock lock = new ReentrantLock(); C. Lock lock = new ReentrantLock(true); D. Lock lock = new ReentrantLock(false);

33.3 The server listens for a connection request from a client using the following statement: A. Socket s = new Socket(ServerName, port); B. Socket s = serverSocket.accept() C. Socket s = serverSocket.getSocket() D. Socket s = new Socket(ServerName);

B. Socket s = serverSocket.accept()

32.17 Which of the following statements are true? A. The javax.swing.SwingUtilities.invokeLater method creates a thread. B. The javax.swing.SwingUtilities.invokeAndWait method runs the code in the event dispatcher thread. C. The javax.swing.SwingUtilities.invokeLater method runs the code in the event dispatcher thread and doesn't return until the event-dispatching thread has executed the specified code. D. GUI event handling is executed in the event dispatcher thread.

B. The javax.swing.SwingUtilities.invokeAndWait method runs the code in the event dispatcher thread. C. The javax.swing.SwingUtilities.invokeLater method runs the code in the event dispatcher thread and doesn't return until the event-dispatching thread has executed the specified code. D. GUI event handling is executed in the event dispatcher thread.

34.18 Analyze the following code: ResultSet resultSet = statement.executeQuery ("select firstName, mi, lastName from Student where lastName " + " = 'Smith'"); System.out.println(resultSet.getString(1)); A. If the SQL SELECT statement returns no result, resultSet is null. B. The program will have a runtime error, because the cursor in resultSet does not point to a row. You must use resultSet.next() to move the cursor to the first row in the result set. Subsequently, resultSet.next() moves the cursor to the next row in the result set. C. resultSet.getString(1) returns the firstName field in the result set. D. resultSet.getString(1) returns the mi field in the result set.

B. The program will have a runtime error, because the cursor in resultSet does not point to a row. You must use resultSet.next() to move the cursor to the first row in the result set. Subsequently, resultSet.next() moves the cursor to the next row in the result set. C. resultSet.getString(1) returns the firstName field in the result set.

34.7 SQL ________ statements may change the contents of a database. A. SELECT B. UPDATE C. DELETE D. INSERT

B. UPDATE C. DELETE D. INSERT

34.21 What is the return value from stmt.executeUpdate("insert into T values (100, 'Smith')") A. void B. an int value indicating how many rows are effected from the invocation C. a value indicating whether the SQL statement has been executed successfully D. an object that contains the status of the execution

B. an int value indicating how many rows are effected from the invocation

34.26 Suppose a callable statement is created as follows: CallableStatement callableStatement = connection.prepareCall( "{call sampleProcedure(?, ?, ?)}"); Assume that the first parameter is an IN parameter with value John. To set this parameter value, use A. callableStatement.setString(0, "John"); B. callableStatement.setString(1, "John"); C. callableStatement.setString(0, 'John'); D. callableStatement.setString(1, 'John');

B. callableStatement.setString(1, "John");

33.12 You can obtain the server's hostname by invoking _________ on an applet. A. getCodeBase().host() B. getCodeBase().getHost() C. getCodeBase().hostName() D. getCodeBase().getHostName()

B. getCodeBase().getHost()

34.10 Where is com.mysql.jdbc.Driver located? A. in the standard Java library bundled with JDK B. in a JAR file mysqljdbc.jar downloadable from the book's Companion Website C. in a JAR file classes12.jar downloadable from the book's Companion Website D. in a JAR file ojdbc14.jar downloadable from the book's Companion Website

B. in a JAR file mysqljdbc.jar downloadable from the book's Companion Website

33.5 When a client requests connection to a server that has not yet started, __________. A. java.net.BindException occurs B. java.net.ConnectionException occurs C. the client is blocked until the server is started D. the client encounters a fatal error and must be terminated

B. java.net.ConnectionException occurs

34.23 Suppose a prepared statement is created as follows: Statement preparedStatement = connection.prepareStatement ("insert into Student (firstName, mi, lastName) " + "values (?, ?, ?)"); To set a value John to the first parameter, use A. preparedStatement.setString(0, "John"); B. preparedStatement.setString(1, "John"); C. preparedStatement.setString(0, 'John'); D. preparedStatement.setString(1, 'John');

B. preparedStatement.setString(1, "John");

32.13 Which of the following method is a static in java.lang.Thread? A. run() B. sleep(long) C. start() D. join() E. setPriority(int)

B. sleep(long)

32.14 Which of the following methods in Thread throws InterruptedException? A. run() B. sleep(long) C. start() D. yield() E. setPriority(int)

B. sleep(long)

33.9 You can invoke ______________ on a Socket object, say socket, to obtain an InetAddress object. A. socket.InetAddress(); B. socket.getInetAddress(); C. socket.obtainInetAddress(); D. socket.retrieveInetAddress();

B. socket.getInetAddress();

34.16 To execute a SELECT statement "select * from Address" on a Statement object stmt, use A. stmt.execute("select * from Address"); B. stmt.executeQuery("select * from Address"); C. stmt.executeUpdate("select * from Address"); D. stmt.query("select * from Address");

B. stmt.executeQuery("select * from Address");

32.8 Which of the following methods in the Thread class are deprecated? A. yield() B. stop(); C. resume(); D. suspend();

B. stop(); C. resume(); D. suspend();

32.10 Which of the following statements are defined in the Object class? A. sleep(long milliseconds) B. wait() C. notify() D. notifyAll() E. toString()

B. wait() C. notify() D. notifyAll() E. toString()

32.18 Suppose there are three Runnable tasks, task1, task2, task3. How do you run them in a thread pool with 2 fixed threads? A. new Thread(task1).start(); new Thread(task2).start(); new Thread(task3).start(); B. ExecutorService executor = Executors.newFixedThreadPool(3); executor.execute(task1); executor.execute(task2); executor.execute(task3); C. ExecutorService executor = Executors.newFixedThreadPool(2); executor.execute(task1); executor.execute(task2); executor.execute(task3); D. ExecutorService executor = Executors.newFixedThreadPool(1); executor.execute(task1); executor.execute(task2); executor.execute(task3);

C. ExecutorService executor = Executors.newFixedThreadPool(2); executor.execute(task1); executor.execute(task2); executor.execute(task3);

34.3 In a relational data model, ________ provides the means for accessing and manipulating data. A. Structure B. Integrity C. Language D. SQL

C. Language D. SQL

32.23 Which of the following are correct statements to create a Lock so the longest-wait thread will obtain the lock first? A. Lock lock = new Lock(); B. Lock lock = new ReentrantLock(); C. Lock lock = new ReentrantLock(true); D. Lock lock = new ReentrantLock(false);

C. Lock lock = new ReentrantLock(true);

34.15 To create a statement on a Connection object conn, use A. Statement statement = conn.statement(); B. Statement statement = Connection.createStatement(); C. Statement statement = conn.createStatement(); D. Statement statement = connection.create();

C. Statement statement = conn.createStatement();

33.8 ______________ models an IP address, which can be used to find the host name and IP address of the client. A. The ServerSocket class B. The Socket class C. The InetAddress class D. The Connection interface

C. The InetAddress class

32.6 Why does the following class have a syntax error? import java.applet.*; public class Test extends Applet implements Runnable { public void init() throws InterruptedException { Thread t = new Thread(this); t.sleep(1000); } public synchronized void run() { } } A. The sleep() method is not invoked correctly; it should be invoked as Thread.sleep(1000). B. You cannot put the keyword synchronized in the run() method. C. The init() method is defined in the Applet class, and it is overridden incorrectly because it cannot claim exceptions in the subclass. D. The sleep() method should be put in the try-catch block. This is the only reason for the compilation failure.

C. The init() method is defined in the Applet class, and it is overridden incorrectly because it cannot claim exceptions in the subclass.

32.3 Analyze the following code: public abstract class Test implements Runnable { public void doSomething() { }; } A. The program will not compile because it does not implement the run() method. B. The program will not compile because it does not contain abstract methods. C. The program compiles fine. D. None of the above.

C. The program compiles fine.

32.30 Analyze the following code. // Test.java: Define threads using the Thread class import java.util.*; public class Test { private Stack stack = new Stack(); private int i = 0; /** Main method */ public static void main(String[] args) { new Test(); } public Test() { // Start threads new Producer().start(); new Consumer().start(); } class Producer extends Thread { public void run() { while (true) { System.out.println("Producer: put " + i); stack.push(new Integer(i++)); synchronized (stack) { notifyAll(); } } } } class Consumer extends Thread { public void run() { while (true) { synchronized (stack) { try { while (stack.isEmpty()) stack.wait(); System.out.println("Consumer: get " + stack.pop()); } catch (InterruptedException ex) { ex.printStackTrace(); } } } } } } A. The program creates two threads: one to add data to the stack and the other to get data from the stack. B. The program has a compilation error on the notifyAll() method in the Producer class because it is not invoked from the stack object. C. The program will throw an exception because the notifyAll() method in the Producer class is not invoked from the stack object. D. The program has a logic error because the lock obtained by the synchronized block for notifyAll in the Producer class is stack and it should be this (i.e., synchronized (this) { notifyAll(); }).

C. The program will throw an exception because the notifyAll() method in the Producer class is not invoked from the stack object.

34.30 Result set meta data are retrieved through ____________. A. a Connection object B. a Statement object C. a ResultSet Object D. a PreparedStatement object

C. a ResultSet Object

32.34 Which of the following methods can be used to obtain a permit from a Semaphore s? A. get() B. ask() C. acquire() D. delete()

C. acquire()

34.27 Suppose a callable statement is created as follows: CallableStatement callableStatement = connection.prepareCall( "{call sampleProcedure(?, ?, ?)}"); Assume that the second parameter is an OUT parameter with value John. To register this parameter, use A. callableStatement.registerOutParameter(0, java.sql.Types.STRING); B. callableStatement.registerOutParameter(1, java.sql.Types.STRING); C. callableStatement.registerOutParameter(2, java.sql.Types.STRING);

C. callableStatement.registerOutParameter(2, java.sql.Types.STRING);

33.10 The ____________ method in the InetAddress class returns the IP address. A. getIP() B. getIPAddress() C. getHostAddress() D. getAddress()

C. getHostAddress()

34.13 A database URL for a MySQL database named test on host panda.armstrong.edu is ________. A. jdbc.mysql.//panda.armstrong.edu/test B. jdbc:mysql:/panda.armstrong.edu/test C. jdbc:mysql://panda.armstrong.edu/test D. jdbc.mysql://panda.armstrong.edu/test

C. jdbc:mysql://panda.armstrong.edu/test

34.12 A database URL for an access database source test is ________. A. test B. jdbcodbc:test C. jdbc:odbc:test D. sun.jdbc:odbc:test

C. jdbc:odbc:test

34.31 What information may be obtained from a ResultSetMetaData object? A. database URL and product name B. JDBC driver name and version C. number of columns in the result set D. number of rows in the result set

C. number of columns in the result set

34.24 If a prepared statement preparedStatement is a SQL SELECT statement, you execute the statement using _________. A. preparedStatement.execute(); B. preparedStatement.executeUpdate(); C. preparedStatement.executeQuery(); D. preparedStatement.query();

C. preparedStatement.executeQuery();

32.35 Which of the following methods can be used to return a permit to a Semaphore s? A. return() B. release() C. send() D. add()

C. send()

32.20 The keyword to synchronize methods in Java is __________. A. synchronize B. synchronizing C. synchronized D. Synchronized

C. synchronized

32.29 Which of the following statements are true? A. The wait(), notify(), and notifyAll() methods must be invoked from a synchronized method or a synchronized block. B. When wait() is invoked, it pauses the thread and releases the lock on the object simultaneously. When the thread is restarted after being notified, the lock is automatically reacquired. C. The notify() method can wake only one waiting thread. D. An exception would occur if no thread is waiting on the object when the notify() method is invoked on the object.

D. An exception would occur if no thread is waiting on the object when the notify() method is invoked on the object.

32.12 When you run the following program, what will happen? public class Test extends Thread { public static void main(String[] args) { Test t = new Test(); t.start(); t.start(); } public void run() { System.out.println("test"); } } A. Nothing is displayed. B. The program displays test twice. C. The program displays test once. D. An illegal java.lang.IllegalThreadStateException may be thrown because you just started thread and thread might have not yet finished before you start it again.

D. An illegal java.lang.IllegalThreadStateException may be thrown because you just started thread and thread might have not yet finished before you start it again.

34.14 To connect to a local MySQL database named test, use A. Connection connection = DriverManager.getConnection(jdbc:mysql://localhost/test); B. Connection connection = DriverManager.connect("jdbc:mysql://localhost/test"); C. Connection connection = DriverManager.getConnection("mysql:jdbc://localhost/test"); D. Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/test");

D. Connection connection = DriverManager.getConnection("jdbc:mysql://localhost/test");

32.5 Analyze the following code: public class Test implements Runnable { public static void main(String[] args) { Test t = new Test(); } public Test() { Thread t = new Thread(this); t.start(); } public void run() { System.out.println("test"); } } A. The program has a compilation error because t is defined in both the main() method and the constructor Test(). B. The program compiles fine, but it does not run because you cannot use the keyword this in the constructor. C. The program compiles and runs and displays nothing. D. The program compiles and runs and displays test.

D. The program compiles and runs and displays test.

33.11 A ServerSocket can connect to ________ clients. A. one B. two C. ten D. an unlimited number of

D. an unlimited number of

32.27 Which method on a condition should you invoke to wake all waiting threads? A. condition.wake(); B. condition.signal(); C. condition.wakeAll(); D. condition.signalAll();

D. condition.signalAll();

32.7 Which of the following expressions must be true if you create a thread using Thread = new Thread(object)? A. object instanceof Thread B. object instanceof Frame C. object instanceof Applet D. object instanceof Runnable

D. object instanceof Runnable

32.15 Given the following code, which set of code can be used to replace the comment so that the program displays time to the console every second? import java.applet.*; import java.util.*; public class Test extends Applet implements Runnable { public void init() { Thread t = new Thread(this); t.start(); } public void run() { for(; ;) { //display time every second System.out.println(new Date().toString()); } } } A. try { sleep(1000); } catch(InterruptedException e) { } B. try { t.sleep(1000); } catch(InterruptedException e) { } C. try { Thread.sleep(1000); } catch(RuntimeException e) { } D. try { Thread.sleep(1000); } catch(InterruptedException e) { }

D. try { Thread.sleep(1000); } catch(InterruptedException e) { }

32.11 You can use the ________ method to force one thread to wait for another thread to finish. A. sleep(long milliseconds) B. yield() C. stop() D. suspend() E. join()

E. join()

33.13 To obtain an ObjectInputStream from a socket, use ________. A. socket.getInputStream() B. socket.getObjectStream() C. socket.getObjectInputStream() D. socket.objectInputStream() E. new ObjectInputStream(socket.getInputStream());

E. new ObjectInputStream(socket.getInputStream());

33.14 To obtain an ObjectOutputStream from a socket, use ________. A. socket.getOutputStream() B. socket.getObjectStream() C. socket.getObjectOutputStream() D. socket.objectOutputStream() E. new ObjectOutputStream(socket.getOutputStream())

E. new ObjectOutputStream(socket.getOutputStream())


संबंधित स्टडी सेट्स

Career Planning and Skill Development Unit 3 Lesson 4: Arts, A/V Technology, and Communication

View Set

Hubspot - Social Media Marketing Certification Exam & Quizzes

View Set

Conducting Psychology Research #4

View Set

American Federal Government Final Exam

View Set

Science 9 - Quest 1 - theories, method

View Set

History of Architecture Exam 1 (weeks 1-5)

View Set