Introduction to Java Programming, Seventh Edition, Y. Daniel Liang
Chapter 30: Networking
Section 30.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.
"127.127.127.1".
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();
Section 30.3 The InetAddress Class
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
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();
10
The ____________ method in the InetAddress class returns the IP address.
A.
getIP()
B.
getIPAddress()
C.
getHostAddress()
D.
getAddress()
Section 30.4 Serving Multiple Clients
11
A ServerSocket can connect to ________ clients.
A.
one
B.
two
C.
ten
D.
an unlimited number of
Section 30.5 Applet Clients
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()
Section 30.6 Sending and Receiving Objects
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());
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())
Section 30.7 Retrieving Files from Web Servers
15
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;
16
To create an InputStream to read from a file on a Web server, you use the method __________ in the URL class.
A.
getInputStream();
B.
obtainInputStream();
C.
openStream();
D.
connectStream();