Developed by Y. Daniel Liang using Java Servlets (Current time is Sat Nov 21 19:13:24 EST 2009)

The questions are to accompany Introduction to Java Programming, 4E by Y. Daniel Liang. Please report errors to y.daniel.liang@gmail.com.

Introduction to Java Programming, 4E has been superseded by Introduction to Java Programming, 5E.

Chapter 18: Networking

Section 18.2 Client/Server Computing
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.

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.

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

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

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.

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. All of the above.

Section 18.6 The URL Class and Viewing Web Pages from Applts
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();

8   To view HTML pages at a given URL url in an applet, you use __________.

A.  
AppletContext context = getAppletContext();
context.showDocument(url);

B.  
AppletContext context = Applet.getAppletContext();
context.showDocument(url);

C.  
AppletContext context = getAppletContext();
context.getDocument(url);

D.  
AppletContext context = Applet.getAppletContext();
context.getDocument(url);

9   To create an InputStream to read from a file on a Web server, you use the class __________.

A. URL;
B. Server;
C. ServerSocket;
D. ServerStream;

Section 18.7 Retrieving Files from Web Servers
10   To create an InputStream to read from a file on a Web server, you use the method __________.
A. getInputStream();
B. obtainInputStream();
C. openStream();
D. connectStream();