Introduction to Java Programming, Includes Data Structures, Eleventh Edition, Y. Daniel Liang

This quiz is for students to practice. A large number of additional quiz is available for instructors using Quiz Generator from the Instructor's Resource Website. Videos for Java, Python, and C++ can be found at https://yongdanielliang.github.io/revelvideos.html.

Chapter 33 Networking


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

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

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

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

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

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

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

Section 33.3 The InetAddress Class
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

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

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

Section 33.4 Serving Multiple Clients
33.11  A ServerSocket can connect to ________ clients.
A. one
B. two
C. ten
D. an unlimited number of

Section 33.5 Applet Clients
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()

Section 33.6 Sending and Receiving Objects
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());

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