SampleExam11(Ch29-31..

advertisement
Name:_______________________ Sample Exam
Covers Chs 29-31
Multiple Choice Questions Only for This Test
Part I: Questions: (1 pts each)
1 You should always invoke the unlock method in the finally
clause.
A. true
B. false
2 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.
B.
C.
D.
try { Thread.sleep(1000); } catch(InterruptedException e) { }
try { sleep(1000); } catch(InterruptedException e) { }
try { Thread.sleep(1000); } catch(RuntimeException e) { }
try { t.sleep(1000); } catch(InterruptedException e) { }
3 Which of the following expressions must be true if you
create a thread using Thread = new Thread(object)?
A.
B.
C.
D.
object
object
object
object
4 How
instanceof Applet
instanceof Thread
instanceof Frame
instanceof Runnable
do you create a condition on a lock?
1
A.
B.
C.
D.
Condition condition = Lock.getCondition();
Condition condition = Lock.newCondition();
Condition condition = lock.getCondition();
Condition condition = lock.newCondition();
5 Which method on a condition should you invoke to causes the
current thread to wait until the condition is signaled?
A.
B.
C.
D.
condition.waited();
condition.await();
condition.waiting();
condition.wait();
6 To run an object on a separate thread, the object must be a
subclass of Thread.
A. true
B. false
7 The Runnable interface is more general than the Thread
class. You can convert any class that extends Thread to a
class that implements Runnable.
A. true
B. false
8 An exception occurs if the resume() method is invoked by a
finished thread object.
A. true
B. false
9 You can set a priority for an object of ThreadGroup using
the setPrority() method.
A. false
B. true
10 You must specify a name for the thread group that you will
create.
A. false
B. true
11 You should not directly invoke the run() method of a thread
object.
A. true
B. false
12
When creating a server on a port that is already in use,
__________.
2
A.
B.
C.
D.
the server encounters a fatal error and must be terminated.
the server is blocked until the port is available.
the server is created with no problems.
java.net.BindException occurs.
13 To obtain an ObjectInputStream from a socket, use ________.
A.
B.
C.
D.
socket.objectInputStream()
socket.getInputStream()
socket.getObjectInputStream()
socket.getObjectStream()
14 You can invoke ______________ on a Socket object, say
socket, to obtain an InetAddress object.
A.
B.
C.
D.
socket.obtainInetAddress();
socket.InetAddress();
socket.retrieveInetAddress();
socket.getInetAddress();
15 To connect to a server running on the same machine with the
client, which of the following can be used for the
hostname?
A.
B.
C.
D.
InetAddress.getLocalHost(),
"127.0.0.1"
"localhost"
All of the above.
16 The server listens for a connection request from a client
using the following statement:
A.
B.
C.
D.
Socket s = serverSocket.accept()
Socket s = new Socket(ServerName);
Socket s = serverSocket.getSocket()
Socket s = new Socket(ServerName, port);
17 The server can create a server socket regardless of whether
the port is in use or not.
A. true
B. false
18 The client can connect to the server regardless of whether
the port is in use or not.
A. true
B. false
19 You cannot get instances of InputStream or OutputStream
because InputStream and OutputStream are abstract classes.
A. true
B. false
3
20 An applet cannot connect to a server program on a Web
server where the applet was loaded.
A. false
B. true
21 You can transmit objects over the socket.
A. false
B. true
22 The URL constructor throws MalformedURLException if the URL
is syntactically incorrect.
A. true
B. false
23 getInputStream() and getOutputStream() are used to produce
InputStream and OutputStream on the socket.
A. false
B. true
24 Which of the following statements are true?
A. You can create an instance of NumberFormat using the static
factory methods in NumberFormat.
B. You can create an instance of DecimalFormat using new
DecimalFormat(Local).
C. DecimalFormat is a subclass of NumberFormat.
D. An instance created using the static factory methods in
NumberFormat is also an instance of DecimalFormat.
E. You can create an instance of NumberFormat using new
NumberFormat(Local).
25 Which of the following are in the java.text package?
A.
B.
C.
D.
E.
DateFormat
SimpleDateFormat
DateFormatSymbols
Date
Locale
26 Which of the following code is correct to obtain hour from
a Calendar object cal?
A.
B.
C.
D.
cal.getHour();
cal.get(Hour);
cal.get(Calendar.HOUR);
cal.hour();
27 How do you create a locale for the United States?
4
A.
B.
C.
D.
new Locale("en", "US");
new Locale("US", "en");
Locale.getLocale("en", "US")
Locale.US;
28 A resource bundle is ___________
A. a Java class file or a text file that provides locale-specific
information.
B. a Java source code the contains image, audio, and text files.
C. an audio file.
D. an image file.
29 To display number in desired format, you have to use the
NumberFormat class or its subclasses.
A. true
B. false
30 You can find all the available locales from a Swing object.
A. true
B. false
31 The locale property is in the Component class, thus, every
Java Swing component has the locale property.
A. true
B. false
32 You can get year, month, day, hour, minute, and second from
an instance of GregorianCalendar.
A. true
B. false
33 You can get hour, minute and second from the Date class.
A. false
B. true
34 The TimeZone class has a static method for obtaining all
the available time zone IDs.
A. false
B. true
35 You can get all the available locales from an instance of
Calendar, Collator, DateFormat, or NumberFormat.
A. false
B. true
5
Keys:
1. A
2. A
3. D
4. D
5. B
6. A
7. A
8. A
9. A
10. B
11. A
12. D
13. D
14. D
15. D
16. A
17. B
18. A
19. B
20. B
21. B
22. B
23. B
24. ACD
25. ABC
26. C
27. AD
28. A
29. A
30. B
31. A
32. A
33. A
34. B
35. B
6
Download