Java III - Final

Ace your homework & exams now with Quizwiz!

A, B, C, D, E

Which of the following statements are true? (Multiple Answers) A. A File object encapsulates the properties of a file or a path, but does not contain the methods for reading/writing. B. You can use the PrintWriter class for outputting text to a file. C. You can use the Scanner class for reading text from a file. D. An input object is also called an input stream. E. An output object is also called an output stream.

C

JSF applications are developed using the _______________________ architecture. A. Modern-View-Controller B. Model-View-Calculator C. Model-View-Controller D. Model-Variable-Controller

C

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

A

17.10 After the following program is finished, how many bytes are written to the file t.dat? import java.io.*; public class Test { public static void main(String[] args) throws IOException { DataOutputStream output = new DataOutputStream(new FileOutputStream("t.dat")); output.writeChar('A'); output.close(); } } A. 2 bytes. B. 4 bytes. C. 8 bytes. D. none of the above.

C

17.11 After the following program is finished, how many bytes are written to the file t.dat? import java.io.*; public class Test { public static void main(String[] args) throws IOException { DataOutputStream output = new DataOutputStream(new FileOutputStream("t.dat")); output.writeChars("ABCD"); output.close(); } } A. 2 bytes. B. 4 bytes. C. 8 bytes. D. 12 bytes. E. 16 bytes.

C

17.12 After the following program is finished, how many bytes are written to the file t.dat? import java.io.*; public class Test { public static void main(String[] args) throws IOException { DataOutputStream output = new DataOutputStream(new FileOutputStream("t.dat")); output.writeUTFString("ABCD"); output.close(); } } A. 2 bytes. B. 4 bytes. C. 6 bytes. D. 8 bytes. E. 10 bytes.

A, B, C, D

17.13 Which of the following statements are true? (Multiple Answers) A. All files are stored in binary format. So, all files are essentially binary files. B. Text I/O is built upon binary I/O to provide a level of abstraction for character encoding and decoding. C. Encoding and decoding are automatically performed by text I/O. D. For binary input, you need to know exactly how data were written in order to read them in correct type and order.

A, B, C, D, E

17.14 Which of the following statements are true? (Multiple Answers) A. ObjectInputStream/ObjectOutputStream enables you to perform I/O for objects in addition for primitive type values and strings. B. Since ObjectInputStream/ObjectOutputStream contains all the functions of DataInputStream/DataOutputStream, you can replace DataInputStream/DataOutputStream completely by ObjectInputStream/ObjectOutputStream. C. To write an object, the object must be serializable. D. The Serializable interface does not contain any methods. So it is a mark interface. E. If all the elements in an array is serializable, the array is serializable too.

D

17.17 To create a file, you can use __________. A. FileOutputStream B. FileWriter C. RandomAccessFile D. All of the above

C

17.18 Which of the following is the legal mode for creating a new RandomAccessFile stream? A. "w" B. 'r' C. "rw" D. "rwx"

C

17.19 What happens if the file test.dat does not exist when you attempt to compile and run the following code? import java.io.*; class Test { public static void main(String[] args) { try { RandomAccessFile raf =new RandomAccessFile("test.dat", "r"); int i = raf.readInt(); } catch(IOException ex) { System.out.println("IO exception"); } } } A. The program does not compile because raf is not created correctly. B. The program does not compile because readInt() is not implemented in RandomAccessFile. C. The program compiles, but throws IOException because the file test.dat doesn't exist. The program displays IO exception. D. The program compiles and runs fine, but nothing is displayed on the console.

A

17.20 With which I/O class can you append or update a file? A. RandomAccessFile() B. OutputStream() C. DataOutputStream() D. None of the above

B

17.3 Which method can you use to find out the number of the bytes in a file using InputStream? A. length() B. available() C. size() D. getSize()

A, B, C, D

17.4 Which of the following statements are true? (Multiple Answers) A. All methods in FileInputStream/FileOutputStream are inherited from InputStream/OutputStream. B. You can create a FileInputStream/FileOutputStream from a File object or a file name using FileInputStream/FileOutputStream constructors. C. The return value -1 from the read() method signifies the end of file. D. A java.io.FileNotFoundException would occur if you attempt to create a FileInputStream with a nonexistent file. E. A java.io.FileNotFoundException would occur if you attempt to create a FileOutputStream with a nonexistent file.

C

17.5 To append data to an existing file, use _____________ to construct a FileOutputStream for file out.dat. A. new FileOutputStream("out.dat") B. new FileOutputStream("out.dat", false) C. new FileOutputStream("out.dat", true) D. new FileOutputStream(true, "out.dat")

E

17.6 What does the following code do? FileInputStream fis = new FileInputStream("test.dat"); A. It creates a new file named test.dat if it does not exist and opens the file so you can write to it. B. It creates a new file named test.dat if it does not exist and opens the file so you can write to it and read from it. C. It creates a new file named test.dat regardless of whether it exists or not and opens the file so you can write to it. D. It creates a new file named test.dat regardless of whether it exists or not and opens the file so you can write to it and read from it. E. It creates a FileInputStream for test.dat if test.dat exists.

B

17.9 After the following program is finished, how many bytes are written to the file t.dat? import java.io.*; public class Test { public static void main(String[] args) throws IOException { DataOutputStream output = new DataOutputStream(new FileOutputStream("t.dat")); output.writeShort(1234); output.writeShort(5678);output.close(); } } A. 2 bytes. B. 4 bytes. C. 8 bytes. D. 16 bytes.

A

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.

B, C, D, E

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

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()

D

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.

B

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

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

D

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) { }

A, B, C, D

32.16 Which of the following statements are true? [multiple answers] 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.

B, C, D

32.17 Which of the following statements are true? [Multiple Answers] 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.

C

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

A, B, C, D

32.21 Which of the following statements are true? [Multiple Answers] 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.

B, C, D

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

A

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

B

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();

A

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();

D

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();

A, B, C

32.28 Which of the following statements are true? [Multiple Answers] 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.

D

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.

C

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

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

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(); }).

A, B, C

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

A, B, C, D, E

32.32 Which of the following statements are true? [Multiple Answers] 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,

C

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()

B

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()

A

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.

C

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.

B, C, D

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

A

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

B

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()

E

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

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())

A

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

B

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

A

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

B

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

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

D

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

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

B

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, C

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)); (multiple answser) 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, D

34.19 Suppose that your program accesses MySQL or Oracle database. Which of the following statements are true? (multiple answers) 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

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

A, B, C

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

B

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');

C

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();

A, D

34.25 Which of the following statements are true? (multiple answers) 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, B, C, D

34.29 What information may be obtained from a DatabaseMetaData object? (multiple answers) 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

C

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

C

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

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

A, B

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

A

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

B

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")

C

35.1 To add the SQL statement "insert into T values (100, 'Smith')" into the batch into a Statement stmt, use A. stmt.add("insert into T values (100, 'Smith')"); B. stmt.add('insert into T values (100, 'Smith')'); C. stmt.addBatch("insert into T values (100, 'Smith')"); D. stmt.addBatch('insert into T values (100, 'Smith')');

A, B, C

35.11 For a JTable to be synchronized with a JDBC RowSet, you may create a table model with the following features: (Multiple Answers) A. The model should extend AbstractTableModel and implement getRowCount(), getColumnCount(), and getValueAt(int row, int column). B. The model should implement RowSetListener and the methods rowSetChanged(RowSetEvent e), rowChanged(RowSetEvent e), cursorMoved(RowSetEvent e). C. You should invoke fireTableStructureChanged() method from rowSetChanged(RowSetEvent e) and rowChanged(RowSetEvent e) to synchronize changes in the RowSet with the the JTable

A

35.12 The index of row and column in JTable is 0-based. The index of row and column in RowSet is 1-based. A. true B. false

C

35.13 You can store images in a database using data type _______. A. varchar2 B. varchar C. BLOB D. CLOB

D

35.14 You can store large text in a database using data type _______. A. varchar2 B. varchar C. BLOB D. CLOB

A

35.16 To get binary data from a column, use _____________ in Statement. A. getBlob() B. getBinaryStream() C. getBinaryData() D. getData()

B

35.17 To set binary data to a column, use _____________ in Statement. A. setBlob() B. setBinaryStream() C. setBinaryData() D. setData()

C

35.2 Invoking executeBatch() returns ________. A. an int value indicating how many SQL statements in the batch have been executed successfully. B. a ResultSet C. an array of counts, each of which counts the number of the rows affected by the SQL command. D. an int value indicating how many rows are effected by the batch execution.

C

35.3 To obtain a scrollable or updateable result set, you must first create a statement using which of the following? A. Statement statement = connection.createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); B. Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY); C. Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); D. Statement statement = connection.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);

A, B, C, D, E

35.4 In a scrollable and updateable result set, you can use ___________ methods on a result set. (Multiple Answers) A. first() B. last() C. insertRow() D. deleteRow() E. updateRow()

C

35.5 RowSet is an extension of _______. A. Connection B. Statement C. ResultSet D. CLOB

A, B, C, D

35.6 You can use a RowSet to __________. (Multiple Answers) A. set a database URL B. set a database username C. set a database password D. set a SQL query statement

D, E

35.7 You may create a RowSet using __________. (Multiple Answers) A. new RowSet() B. new JdbcRowSet() C. new CachedRowSet() D. new JdbcRowSetImpl() E. new CachedRowSetImpl()

D

35.8 To move the cursor to the 2nd row in a RowSet, use _________. A. next(2) B. first() C. next() D. absolute(2) E. last()

B

35.9 To update a String column in a RowSet, use _________. A. updateString("newValue") B. updateString("columnName", "newValue") C. updateString("newValue", "columnName") D. updateObject("newValue", "columnName")

C

36.1 How do you set a button jbt's text to a character with the Unicode 13AE? A. jbt.setText("13AE"); B. jbt.setText("\13AE"); C. jbt.setText("\u13AE"); D. jbt.setText("/u13AE"); E. jbt.setText('\u13AE');

A, C, D

36.10 Which of the following statements are true? (multiple answers) A. SimpleDateFormat is a subclass of DateFormat. B. DateFormatSymbols is a subclass of SimpleDateFormat. C. SimpleDateFormat enables you to choose any user-defined pattern for date and time formatting. D. You can obtain localizable date-time formatting data, such as the names of the months, the names of the days of the week, and the time zone data, from an instance of DateFormatSymbols.

A, B, C

36.12 Which of the following are in the java.text package? (multiple answers) A. DateFormatSymbols B. DateFormat C. SimpleDateFormat D. Date E. Locale

A, B, C

36.13 Which of the following code is correct to create an instance for formatting numbers? (multiple answers) A. NumberFormat.getInstance(); B. NumberFormat.getNumberInstance(locale); C. NumberFormat.getInstance(locale); D. NumberFormat.getNumberFormatInstance(locale);

A, B

36.14 Which of the following code is correct to create an instance for formatting numbers in currency? (multiple answers) A. NumberFormat.getCurrencyInstance(locale); B. NumberFormat.getCurrencyInstance(); C. NumberFormat.currencyInstance(locale); D. NumberFormat.currencyInstance();

A, B

36.15 Which of the following code is correct to create an instance for formatting numbers in percent? (multiple answers) A. NumberFormat.getPercentInstance(locale); B. NumberFormat.getPercentInstance(); C. NumberFormat.percentInstance(locale); D. NumberFormat.percentInstance();

A, B, C, D

36.16 Which of the following are valid methods in NumberFormat? (multiple answers) A. format(double) B. format(long) C. setMaximumIntegerDigits(int) D. setMinimumIntegerDigits(int)

A

36.17 Which of the following code displays the numbers with at least two digits before and after the decimal point? A. NumberFormat numberForm = NumberFormat.getNumberInstance(); DecimalFormat df = (DecimalFormat)numberForm;<br>df.applyPattern("00.00"); B. NumberFormat numberForm = NumberFormat.getNumberInstance(); numberForm.setMaximumFractionDigits(2); numberForm.setMinimumFractionDigits(2); C. NumberFormat numberForm = NumberFormat.getNumberInstance();<br>numberForm.setMaximumFractionDigits(2);

B

36.18 Suppose that NumberFormat currencyFormat = NumberFormat.getCurrencyInstance(Locale.US). Which of the following statement is legal? A. Number number = NumberFormat.parse("$5,000.56"); B. Number number = currencyFormat.parse("$5,000.56"); C. Number number = currencyFormat.parseCurrency("$5,000.56"); D. Number number = currencyFormat.parse("5,000.56");

A, D, E

36.19 Which of the following statements are true? (multiple answers) A. DecimalFormat is a subclass of NumberFormat. B. You can create an instance of DecimalFormat using new DecimalFormat(Local). C. You can create an instance of NumberFormat using new NumberFormat(Local). D. You can create an instance of NumberFormat using the static factory methods in NumberFormat. E. An instance created using the static factory methods in NumberFormat is also an instance of DecimalFormat.

A, C

36.2 How do you create a locale for the United States? (multiple answers) A. new Locale("en", "US"); B. new Locale("US", "en"); C. Locale.US; D. Locale.getLocale("en", "US")

C

36.21 Suppose you apply the pattern "00.0##" on a DecimalFormat object f using f.applyPattern("00.0##"). What is the return value from decimalFormat.format(111.2226)? A. 11.223 B. 111.222 C. 111.223 D. 11.2226

E

36.22 Suppose you apply the pattern "00.0##%" on a DecimalFormat object f using f.applyPattern("00.0##%"). What is the return value from decimalFormat.format(111.2226)? A. 11.223% B. 111.222% C. 11122.3% D. 1122.3% E. 11122.26%

B

36.23 A resource bundle is ___________. A. a Java source code that contains image, audio, and text files B. a Java class file or a text file that provides locale-specific information C. an image file D. an audio file

C

36.24 Which of the following code is correct to create an instance of ResourceBundle? A. ResourceBundle.getBundle(); B. ResourceBundle.getBundle(locale); C. ResourceBundle.getBundle(resourcefilename); D. ResourceBundle.getBundle(resourcefilename, locale);

C

36.4 Which of the following methods is correct to obtain the available locales in the classes Calendar, Collator, DateFormat, and NumberFormat? A. getLocales() B. getAllLocales() C. getAvailableLocales() D. availableLocales()

D

36.6 Which of the following set of code lines displays the current time in locale sensitive format? A. GregorianCalendar gcal = new GregorianCalendar(); System.out.println(gcal.toString()); B. Date d = new Date(); System.out.println(d.toString()); C. GregorianCalendar gcal = new GregorianCalendar(new TimeZone("CST")); System.out.println(gcal.toString()); D. GregorianCalendar gcal = new GregorianCalendar(); DateFormat myFormat = DateFormat.getDateTimeInstance(); myFormat.setTimeZone(TimeZone.getTimeZone("CST")); System.out.println(myFormat.format(gcal.getTime()));

D

36.7 Which of the following code is correct to obtain hour from a Calendar object cal? A. cal.getHour(); B. cal.hour(); C. cal.get(Hour); D. cal.get(Calendar.HOUR);

A, C

37.10 Java servlets are better than the CGI programs because ______________. (multiple answers) A. servlets are written in Java while CGI programs are written in Perl or other languages. you can develop servlets with the support of Java API for accessing databases and network resources B. servlets are dynamically executed C. for each CGI execution, the Web browser spawns a new process to execute a CGI program. However, all servlets are executed within the servlet engine. Each execution of a servlet is handled as a thread by the servlet engine. So, servlets runs faster than CGI programs D. servlet programs can run on any Web server

D

37.11 Apache Tomcat is a ________. A. Servlet B. Java program C. Web server D. Web server that is capable of running Java programs

C

37.12 A servlet is an instance of __________. A. the Object class B. the Applet class C. the HttpServlet class D. the HTTPServlet class

C

37.13 To compile a Java servlet program, the ___________ file must be in the classpath. A. TomcatRootDir\servlet.jar B. TomcatRootDir\common\servlet.jar C. TomcatRootDir\common\lib\servlet.jar D. TomcatRootDir\common\bin\lib\servlet.jar

D

37.14 If your servlet class file does not have a package statement, the servlet .class file must be placed in ________ by default. A. the same directory with the .java file. B. TomcatRootDir\webapps\WEB-INF\classes C. TomcatRootDir\webapps\examples\WEB-INF D. TomcatRootDir\webapps\examples\WEB-INF\classes

D

37.15 If your servlet class file has a package statement package chapter33, the servlet .class file must be placed in ________ by default. A. the same directory with the .java file. B. TomcatRootDir\webapps\WEB-INF\classes C. TomcatRootDir\webapps\examples\WEB-INF\classes D. TomcatRootDir\webapps\examples\WEB-INF\classes\chapter33

A

37.16 Before starting Tomcat, you have to set the environment variable JAVA_HOME to _______ A. JDKHomeDir B. JDKHomeDir/bin C. JDKHomeDir/bin/java D. JDKHomeDir/java

D

37.17 To start the Tomcat servlet engine, use the command __________ from the TomcatRootDir\bin directory. A. java TomcatServlet B. start Tomcat C. start D. startup

A

37.19 Suppose the servlet class named Test does not have the package statement, by default, you use ________ to invoke it. A. http://localhost:8080/examples/servlet/Test B. http://localhost:8080/examples/servlet/test C. http://localhost:8080/Test D. http://localhost:8080/test Your answer C is incorrect Click here to show the correct answer

A

37.2 In a URL query string, the ______ symbol separates the program from the parameters. A. ? B. = C. & D. + E. -

A

37.20 The _________ interface defines the methods that all servlets must implement. A. javax.servlet.Servlet B. HttpServlet C. ServletRequest D. ServletResponse

A

37.22 The _________ class defines a servlet for the HTTP protocol. A. javax.servlet.http.HttpServlet B. Servlet C. HttpServletRequest D. HttpServletResponse

A

37.23 _________ is a subinterface of ServletRequest. A. HttpServletRequest B. HttpServletResponse C. HttpServlet D. Servlet

A

37.24 Every doXxx method in the HttpServlet class has a parameter of the __________ type, which is an object that contains HTTP request information, including parameter name and values, attributes, and an input stream. A. HttpServletRequest B. HttpServletResponse C. HttpSession D. Cookie

B

37.25 Every doXxx method in the HttpServlet class has a parameter of the _____________ type, which is an object that assists a servlet in sending a response to the client. A. HttpServletRequest B. HttpServletResponse C. HttpSession D. Cookie

A

37.26 Suppose the two parameters in the doGet or doPost method are request and response. To specify HTML content type sent to the client, invoke ___________. A. response.setContentType("text/html") B. request.setContentType("text/html") C. response.setContentType("html") D. request.setContentType("html")

B

37.3 In a URL query string, the parameter name and value are associated using the ____ symbol. A. ? B. = C. & D. + E. -

D

37.34 To access Oracle or MySQL from servlet, where the Oracle and MySQL jar files should be placed? A. in the class directory of the servlet source code B. in the class directory of the servlet class code C. TomcatRootDir\webapps\WEB-INF\classes D. TomcatRootDir\common\lib

A, B, C

37.35 You can use __________ to implement session tracking in servlets. (multiple answers) A. HTML hidden values in a form B. the Cookie class C. the HttpSession class

C

37.37 To create a cookie for lastName with value Smith, use ____________. A. new Cookie("Smith", "lastName"); B. new Cookie(Smith, lastName); C. new Cookie("lastName", "Smith"); D. new Cookie(lastName, \Smith);

A

37.38 Suppose the two parameters in the doGet or doPost method are request and response. To send a cookie to a client, use ____________. A. response.addCookie(cookie) B. response.sendCookie(cookie) C. request.addCookie(cookie) D. request.sendCookie(cookie)

C

37.39 Suppose the two parameters in the doGet or doPost method are request and response. To retrieve a cookie from a client, use ____________. A. response.retrieveCookie() B. response.getCookie() C. You have to use request.getCookies() to obtain all cookies in an array D. You have to use request.getCookie() to obtain a cookie

C

37.4 In a URL query string, parameter pairs are separated using the ___ symbol. A. ? B. = C. & D. + E. -

B

37.40 For an instance of Cookie, say cookie, to retrieve the name of the cookie, use ____________. A. cookie.getValue() B. cookie.getName() C. You have to use cookie.getNames() to obtain all values in an array. D. You have to use cookie.getValues() to obtain all values in an array.

D

37.41 By default, how long does a cookie last? A. 24 hours B. 30 days C. 365 days D. By default, a newly created cookie persists until the browser exits.

B

37.42 Suppose the two parameters in the doGet or doPost method are request and response. To create an HTTP session, use ____________. A. request.createSession() B. request.getSession() C. response.createSession() D. response.getSession()

B

37.43 For a HttpSession, say session, how do you set an attribute pair with name lastName and value Smith? A. session.setValue("lastName", "Smith") B. session.setAttribute("lastName", "Smith") C. session.value("lastName", "Smith") D. session.attribute("lastName", "Smith")

D

37.5 In a URL query string, the ____ symbol denotes a space character. A. ? B. = C. & D. + E. -

C

37.6 The GET and POST methods are specified in _________. A. a CGI program B. a Java program C. an HTML form D. a URL string

A, B, C, D

37.7 Which of the following statements are true? (multiple answers) A. When issuing a request from an HTML form, either a GET method or a POST method can be used. The form explicitly specifies which of the two is used. B. If the GET method is used, the data in the form are appended to the request string as if they were submitted using a URL. C. If the POST method is used, the data in the form are packaged as part of the request file. The server program obtains the data by reading the file. D. The POST method always triggers the execution of the corresponding CGI program. The GET method may not cause the CGI program to be executed if the previous same request is cached in the Web browser.

B

37.8 The _______ method ensures that a new Web page is generated. A. GET B. POST C. DELETE D. UPDATE

A

37.9 If your request is not time-sensitive, such as finding the address of a student in the database, use the __________ method to speed up the performance. A. GET B. POST C. DELETE D. UPDATE

D

38.1 A JSP file ends with __________. A. .java extension B. .html extension C. .shtml extension D. .jsp extension

D

38.10 ________ is a statement that gives the JSP engine information about the JSP page. A. A JSP implicit object B. A JSP scriptlet C. A JSP expression D. A JSP directive

A

38.11 The ________ directive lets you provide information for the page, such as importing classes and setting up content type. The page directive can appear anywhere in the JSP file. A. page B. include C. tablib D. import

A, B, C

38.12 A class is a JavaBeans component if ____________________. A. it is a public class B. it has a public constructor with no arguments C. it is serializable.

C

38.2 You can run JSP from _____________. A. any Web server B. any JVM C. any Web server that supports Java servlet and JSP D. any Web browser

A, D

38.3 Which of the following statements are true? (Multiple Answers) A. JSP is translated into Java servlet by a Web server when a JSP is called. B. JSP is translated into HTML by a Web server when a JSP is called. C. JSP is translated into XML by a Web server when a JSP is called. D. You can embed Java code in JSP.

A, B, C

38.4 _______________ is a JSP expression. (Multiple Answers) A. <%= i %> B. <%= Math.pow(2, 3) %> C. <%= new Date().toString() %> D. <% for (int i = 0; i <= 10; i++) { %>

D

38.5 _______________ is a JSP scriptlet. A. <%= i %> B. <%= Math.pow(2, 3) %> C. <%! private long computeFactorial(int n) { if (n == 0)return 1;else return n * computeFactorial(n - 1); } %> D. <% for (int i = 0; i <= 10; i++) { %> E. <!-- HTML Comment --%>

C

38.6 _______________ is a JSP declaration. A. <%= i %> B. <%= Math.pow(2, 3) %> C. <%! private long computeFactorial(int n) { if (n == 0) return 1; else return n * computeFactorial(n - 1); } %> D. <% for (int i = 0; i <= 10; i++) { %> E. <!-- HTML Comment -->

B

38.7 _______________ is a JSP comment. A. <%= i %> B. <%-- i --%> C. <%! private long computeFactorial(int n) { if (n == 0) return 1; else return n * computeFactorial(n - 1); } %> D. <% for (int i = 0; i <= 10; i++) { %> E. <!-- HTML Comment -->

A, B, C, D, E

38.8 Which of the following is a JSP implicit object? (Multiple Answsers) A. request B. response C. out D. session E. application

B

38.9 The JSP explicit object out is actually _________. A. response.getOutputStream() B. response.getWriter() C. request.getOutputStream() D. request.getWriter() E. application

C

39.1 ____ completely separates Web UI from Java code so the application developed using JSF is easy to debug and maintain. A. Java servlet B. JSP C. JSF D. PHP E. JavaScript

A, B, C

39.2 You can use NetBeans 6 to develop _______ applications. (Multiple Answers) A. Java servlet B. JSP C. JSF D. PHP

A, B, C, D

39.3 Which of the following are JSF life-cycle methods? (Multiple Answers) A. init() B. preprocess() C. prerender() D. destroy()

A, B, C, D, E

41.1 Which of the following statements are correct? (Multiple Answers) A. The computer on which a Web service resides is referred to as a server. B. The server needs to make the service available to the client, known as publishing a Web service. C. Using a Web service from a client is known as consuming a Web service. D. A client interacts with a Web service through a proxy object. E. The proxy object facilitates the communication between the client and the Web service.

A, B, C, D, E

7.2 Which of the following statements are true? (Multiple Answers) A. Text I/O is built upon binary I/O to provide a level of abstraction for character encoding and decoding. B. Text I/O involves encoding and decoding. C. Binary I/O does not require conversions. D. Binary I/O is more efficient than text I/O, because binary I/O does not require encoding and decoding. E. Binary files are independent of the encoding scheme on the host machine and thus are portable.

A

7.27 Suppose the two parameters in the doGet or doPost method are request and response. To send output to a client, create a PrintWriter using _____________. A. response.getWriter() B. response.getPrintWriter() C. response.writer() D. response.getWrite()

D

7.7 Which type of exception occurs when creating a DataInputStream for a nonexistent file? A. FileNotExist B. FileNotExistException C. FileNotFound D. FileNotFoundException

B

7.8 Which of the following statements is correct to create a DataOutputStream to write to a file named out.dat? A. DataOutputStream outfile = new DataOutputStream(new File("out.dat")); B. DataOutputStream outfile = new DataOutputStream(new FileOutputStream("out.dat")); C. DataOutputStream outfile = new DataOutputStream(FileOutputStream("out.dat")); D. DataOutputStream outfile = new DataOutputStream("out.dat");

C

In a managed JavaBean, a _________ is defined with a getter and a setter method. A. instance variable B. attribute C. property D. behavior


Related study sets

chapter 26 taxes and assessments

View Set

MADM 428 Quiz 2 (performance improvement)

View Set

BIOL 1322 Nutrition & Diet Therapy Chapter 2 Smart Book

View Set

Chapter 10 - Sociology: Race and Ethnicity

View Set