Name:______
Covers Chs 39-43 / Sample Exam

Multiple Choice Questions Only for This Test

Part I: Questions: (1 pts each)

1 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. HttpServletResponse

B. HttpServletRequest

C. HttpSession

D. Cookie

2 To start the Tomcat servlet engine, use the command ______from the TomcatRootDir\bin directory.

A. start

B. startup

C. start Tomcat

D. java TomcatServlet

3 Which of the following creates a check box in an HTML form?

A. <input type="radio" name="gender" value="M" checked>

B. <textarea name="remarks" rows="3" cols="56"</textarea>

C. Major <select name="major" size="1"> <option value="CS">Computer Science<option value="Math">Mathematics<option>English<option>Chinese</select>

D. <input type="checkbox" name="tennis"> Tennis

E. <input type="text" name="mi" size="1">

4 ______is a subinterface of ServletRequest.

A. Servlet

B. HttpServletRequest

C. HttpServletResponse

D. HttpServlet

5 You can use ______to implement session tracking in servlets.

A. the Cookie class

B. HTML hidden values in a form

C. the HttpSession class

6 The ______interface defines the methods that all servlets must implement.

A. HttpServlet

B. ServletResponse

C. javax.servlet.Servlet

D. ServletRequest

7 Before starting Tomcat, you have to set the environment variable JAVA_HOME to ______

A. JDKHomeDir/java

B. JDKHomeDir/bin/java

C. JDKHomeDir/bin

D. JDKHomeDir

8 The code for loading a JDBC driver and connecting to a database should be invoked from _____ in a servlet.

A. the doPut method

B. the init method

C. the destroy method

D. the doGet method

9 Every doXxx method in the HttpServlet class has a parameter of the HttpServletResponse type, which is an object that assists a servlet in sending a response to the client.

A. HttpSession

B. Cookie

C. HttpServletResponse

D. HttpServletRequest

10 Apache Tomcat is a ______.

A. Servlet

B. Java program

C. Web server

D. Web server that is capable of running Java programs.

11 For an instance of Cookie, say cookie, to retrieve the name of the cookie, use ______.

A. cookie.getVlaue()

B. cookie.getName()

C. You have to use cookie.getValues() to obtain all values in an array.

D. You have to use cookie.getNames() to obtain all values in an array.

12 If your servlet class file does not have a package statement, the servlet .class file must be placed in ______by default.

A. TomcatRootDir\webapps\examples\WEB-INF

B. TomcatRootDir\webapps\WEB-INF\classes

C. the same directory with the .java file.

D. TomcatRootDir\webapps\examples\WEB-INF\classes

13 Suppose the two parameters in the doGet or doPost method is request and response. To send output to a client, create a PrintWriter using ______.

A. response.getWrite()

B. response.writer()

C. response.getPrintWriter()

D. response.getWriter()

14 The ______method is called when the servlet is first created, and is not called again as long as the servlet is not destroyed.

A. service

B. destroy

C. init

D. getServletInfo

15 In a URL query string, the parameter name and value are associated using the ____ symbol.

A. =

B. -

C. ?

D. +

E. &

16
JSP files end with ______.

A. .shtml extension

B. .html extension

C. .java extension

D. .jsp extension

17 Which of the following statements are true?

A. JSP is translated into HTML by a Web server when a JSP is called.

B. JSP is translated into Java servlet by a Web server when a JSP is called.

C. YOu can embed Java code in JSP.

D. JSP is translated into XML by a Web server when a JSP is called.

18 ______is a JSP declaration.

A. <%! private long computeFactorial(int n) { if (n == 0) return 1; else return n * computeFactorial(n - 1); } %>

B. <!-- HTML Comment -->

C. <% for (int i = 0; i <= 10; i++) { %>

D. <%= Math.pow(2, 3) %>

E. <%= i %>

19 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. import

C. tablib

D. include

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

21 ______is a JSP expression.

A. <%= Math.pow(2, 3) %>

B. <%= new Date().toString() %>

C. <%= i %>

D. <% for (int i = 0; i <= 10; i++) { %>

22 Which of the following is a JSP implicit object?

A. response

B. application

C. out

D. session

E. request

23 ______is a JSP scriptlet.

A. <!-- HTML Comment --%>

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. <%= Math.pow(2, 3) %>

24 The JSP explicit object out is actually ______.

A. response.getWriter()

B. response.getOutputStream()

C. request.getOutputStream()

D. application

E. request.getWriter()

25 ______is a JSP comment.

A. <%-- i --%>

B. <!-- HTML Comment -->

C. <%= i %>

D. <% for (int i = 0; i <= 10; i++) { %>

E. <%! private long computeFactorial(int n) { if (n == 0) return 1; else return n * computeFactorial(n - 1); } %>

26 Assume that the file named policy contains the permission for registering a remote object with an RMI registry. To run the program (e.g., RegisterWithRMIServer) that registers a remote object with an RMI registry, use the command ______from the command window.

A. java RegisterWithRMIServer

B. java –Djava.security.policy=policy RegisterWithRMIServer

C. java –Dpolicy=policy RegisterWithRMIServer

D. java RegisterWithRMIServer java –Djava.security.policy=policy

27 To start an RMI registry, use ______from the command window.

A. rmiregistry

B. start rmiregistry

C. rmiregistry 7000

D. start rmiregistry 7000

28 ______is an object that resides on the client host and serves as a surrogate for the remote server object.

A. Server object interface

B. Server implementation

C. RMI Registry

D. Server Skeleton

E. Server stub

29 ______is a class that implements the remote object interface.

A. Server object interface

B. Server Skeleton

C. Server stub

D. Server implementation

E. RMI Registry

30 To register a remote object o with a name t at port 7000 on host panda.armstrong.edu, use

A. Naming.rebind("rmi://panda.armstrong.edu:7000/t", o);

B. Name.bind("rmi://panda.armstrong.edu:7000/t", o);

C. Naming.bind("rmi://panda.armstrong.edu:7000/t", o);

D. Name.rebind("rmi://panda.armstrong.edu:7000/t", o);

31 ______is an object that resides on the server host, communicates with the stub and the actual server object.

A. Server object interface

B. RMI Registry

C. Server stub

D. Server Skeleton

E. Server implementation

32 ______is a utility that registers remote objects and provides naming services for locating objects.

A. Server stub

B. Server object interface

C. Server Skeleton

D. Server implementation

E. RMI Registry

33 Each remote object has a unique name identified by an URL with the protocol rmi as follows:

A. http://host:port/name

B. //host:port/name

C. http://host/name

D. rmi://host:port/name

34 ______provides the naming services for the server to register the object and for the client to locate the object.

A. Server stub

B. RMI Registry

C. Server implementation

D. Server Skeleton

E. Server object interface

35 Which of the following statements are true when passing arguments in a remoter method call.

A. Primitive data types, such as char, int, double, or boolean, are passed by value like a local call.

B. Remote object types are passed differently from local objects. When a client invokes a remote method with a parameter of a remote object type, the stub of the remote object is passed. The server receives the stub and manipulates the parameter through it.

C. Local object types, such as java.lang.String, are also passed by value, but this is completely different from passing an object parameter in a local call. Any object can be used as a parameter in a remote call as long as it is serializable. The stub serializes the object parameter and sends it in a stream across the network. The skeleton deserializes the stream into an object.

D. When a client invokes a remote method with parameters, passing the parameters is handled by the stub and the skeleton.

36
RMI is about ______.

A. accessing remote objects and invoking methods from remote objects.

B. java.lang.Cloneable

C. passing objects between a server and a client

D. passing primitive data between a server and a client

37 Which of the following statements are true?

A. RMI enables you to program at a higher level of abstraction. It hides the details of socket server, socket, connection, and sending or receiving data. It even implements a multithreading server under the hood, whereas with socket-level programming you have to explicitly implement threads for handling multiple clients.

B. In socket-level programming, a client operation to send data requires a server operation to read it. The implementation of client and server at the socket-level is tightly synchronized.

C. RMI clients can directly invoke the server method, whereas socket-level programming is limited to passing values.

D. RMI applications are scalable and easy to maintain. You can change the RMI server or move it to another machine without modifying the client program except for resetting the URL to locate the server.

38 A remote object must be an instance of ______.

A. java.rmi.Remote

B. java.rmi.RemoteObject

C. java.io.Serializable

D. java.lang.Cloneable

39 To locate a remote object with a name t at port 7000 on host panda.armstrong.edu, use

A. Remote remoteObj = Name.lookup("rmi://panda.armstrong.edu:7000/t");

B. Remote remoteObj = Name.lookup("//panda.armstrong.edu:7000/t");

C. Remote remoteObj = Name.lookup("http://panda.armstrong.edu:7000/t");

D. Remote remoteObj = Naming.lookup("rmi://panda.armstrong.edu:7000/t");

40 ______is a subinterface of java.rmi.Remote that defines the methods for the server object.

A. Server stub

B. Server implementation

C. Server object interface

D. RMI Registry

E. Server Skeleton

Keys:

1. B
2. B
3. D
4. B
5. ABC
6. C
7. D
8. B
9. C
10. D
11. B
12. D
13. D
14. C
15. A
16. D
17. BC
18. A
19. A
20. ABC
21. ABC
22. ABCDE
23. D
24. A
25. A
26. B
27. BD
28. E
29. D
30. AC
31. D
32. E
33. B
34. B
35. ABCD
36. A
37. ABCD
38. A
39. D
40. C

1