Вы находитесь на странице: 1из 16

( Word to PDF Converter - Unregistered )

http://www.Word-to-PDF-Converter.net
Advanced Java Test

Time: 1.5 hrs

MARKS:45

1. Consider the following code:


<html><body>
<% x=3; %>
<% int x=5; %>
<%! int x=7; %>
x = <%=x%>, <%=this.x%>
</body></html>
Which one of the following will be the correct output of the above code?

a. x = 3, 5 b. x = 3, 7 c. x = 5, 3 d. x = 5, 7 e. Compilation Error

2. Which of the following does the J2EE platform consist of?

a) Services

b) APIs

c) Protocols

d) All of these

3. Which of the following gives the services provided by container?

a) lifecycle management

b) deployment

c) security

d) threading

e) All of these

4. Where does web tier components run in J2EE multitiered Applications?

a. Client tier b. J2EE Server c. EIS tier d. IIS

5. Which of the following Transaction interface allows operations to be performed


against the transaction in the target Transaction object and to start a transaction
explicitly?
a) Use package javax.transaction

b) Use interface javax.transaction.TransactionManager

c) Use interface javax.transaction.Transaction

d) None of these

6.In J2EE packaging and deployment process, which of the role below creates and
modifies the deployment descriptor?
( Word to PDF Converter - Unregistered )
http://www.Word-to-PDF-Converter.net
a) Application component provider

b) Application assembler

c) Application Deployer

d) System Administrator

7. What object will the component create to look up the environment naming
context in InitialContext under the name java:comp/env?

a) java.naming.InitialContext

b) javax.naming.Context

c) javax.naming.InitialContext

d) javax.naming.NaminingContext

8. Consider the following scenario:

Server A does not have graphical display options so that the installation has to
happen as command-line installation.

Which of the following is used by installer to run from the command line, to specify
the configuration set, during the installation?
a. installgroup and install path options

b. installType and installpath options

c. installGroup and installLocation options

d. installGroup and installsite options

e. installState and installsite options

9. Which of the following is the deployment descriptor file of a web application?


Assuming that the name of the Web application is BankApp.
a) BankApp.xml

b) WebApp.xml

c) server.xml

d) deployment.xml

e) Web.xml

9. Which of the following best represents the sequence of events in a servlet


lifecycle?\

a) class instantiation,
class loading,
service method,
( Word to PDF Converter - Unregistered )
http://www.Word-to-PDF-Converter.net
init method,
delete method

b) class loading,
class instantiation,
service method,
init method,
delete method

c) class loading,
class instantiation,
service method,
init method,
destroy method

d) class loading,
class instantiation,
init method,
service method,
delete method

e) class loading,

class instantiation,

init method

service method,

destroy method

10. Which of the following JSP tags can be used to print the value of an expression
to the output stream? (Choose 2)
a) <%@ %>

b) <%! %>

c) <% %>

d) <%= %>

e) <%-- --%>

11. Given the following Code:-

<%-- file one.jsp begins here--%>

<%@page import =”java.util.*” contentType=”text/html” session=”true”

<%ArrayList al=new ArrayList(0);

al.add(“Jack Russell”);
( Word to PDF Converter - Unregistered )
http://www.Word-to-PDF-Converter.net

al.add(“Labrador”);

al.add(“Great Dane”);%>

<@include file=”two.jsp”%>

<%--file two.jsp begins--%>

<%@page import=”java.util.*” contentType=”text/html”%>

<%for (int i=0;i <%}%>

<%=al.get(i) %>

<%-- two.jsp ends here--%>

Which two of the following statements are true about the above two JSP page

sources, given that client is requesting one.jsp?[Choose all that apply]

a. Translation will fail because the import attribute of the page directive is

repeated across the page source.

b. The order of the import and contentType attributes in both JSP page

sources is immaterial.

c. Removing the Session attribute from one.jsp will make no difference to

the generated servlet code

d. The local variable al in two.jsp will not be recognized

e. The import,contentType,and session attributes should appear in separate page

directives

12. Every page of your web site must include a common set of navigation menus at

the top of the page. This menu is static HTML and changes frequently, so you have

decided to use JSP's static import mechanism. Which JSP code snippet

accomplishes this goal?

a. <%@ import file='/common/menu.html' %>

b. <%@ page import='/common/menu.html' %>


( Word to PDF Converter - Unregistered )
http://www.Word-to-PDF-Converter.net

c. <%@ import page='/common/menu.html' %>

d. <%@ include file='/common/menu.html' %>

13. Given the JSP code and the Classic tag handler code:

5. public int doStartTag() throws JspException {

6. // insert code here

7. // return int

8. }Assume there are no other "foo" attributes in the web application.

Which invocation on the pageContext object, inserted at line 6, assigns "bar" to the

variable x?

a. String x = (String) pageContext.getAttribute("foo");

b. String x = (String) pageContext.getRequest().getAttribute("foo");

c. It is NOT possible to access the pageContext object from within doStartTag

d. String x = (String) pageContext.getAttribute("foo",PageContext.ANY_SCOPE);

14. Which implicit object is used in a JSP page to retrieve values associated with

entries in the deployment descriptor?

a. config b. request c. session d. application

15. Which one of the following exceptions may be thrown by the _jspService()

method?

a. javax.servlet.ServletException

b. javax.servlet.jsp.JSPException

c. javax.servlet.ServletException and javax.servlet.jsp.JSPException

d. javax.servlet.ServletException and java.io.IOException

e. None of these
( Word to PDF Converter - Unregistered )
http://www.Word-to-PDF-Converter.net

16. You are writing a JSP that includes scriptlet code to declare a List variable and

initializes that variable to an ArrayList object. Which two JSP code snippets can you

use to import these list types? (Choose two.)

a. <%! import java.util.*; %>

b. <%! import java.util.List; import java.util.ArrayList; %>

c. <%@ page import='java.util.List' import='java.util.ArrayList' %>

d. <%@ import types='java.util.List' types='java.util.ArrayList' %>

e. <%@ page import='java.util.List,java.util.ArrayList' %>

17. You have built a collection of custom tags for your web application. The TLD file

is located in the file: /WEB-INF/myTags.xml. You refer to these tags in your JSPs

using the symbolic name: myTags. Which deployment descriptor element must you

use to make this link between the symbolic name and the TLD file name?

a. myTags/WEB-INF/myTags.xml

b. myTags/WEB-INF/myTags.xml

c. myTags/WEB-INF/myTags.xml

d. myTags/WEB-INF/myTags.xml

18. You need to create a JavaBean object that is used only within the current JSP

page. It must NOT be accessible to any other page including those that this page

might import. Which JSP standard action can accomplish this goal?

a. <jsp:useBean id='pageBean' type='com.example.MyBean' >

b. <jsp:useBean id='pageBean' class='com.example.MyBean' >

c. <jsp:makeBean id='pageBean' class='com.example.MyBean' >

d. <jsp:useBean name='pageBean' class='com.example.MyBean' >


( Word to PDF Converter - Unregistered )
http://www.Word-to-PDF-Converter.net

19. A resource that is included using the RequestDispatcher.include method will

share attributes of the originating resource.

State true or false.

a. True b. False

20. Which of the following is a correct JSP declaration for a variable of class
java.util.Date?
a) <%! Date d = new Date() %>

b) < %@Date d=new Date()% >

c) <%! Date d=new DATE();%>

d) <%$ Date d = new Date() %>

21. Consider the following HTML page code:

<html><body>
<a href="/servlet/HelloServlet">POST</a>
</body></html>
Assume that there is a HelloServlet servlet Class defined.

Which method of HelloServlet class will be invoked when the hyperlink displayed by
the above page is clicked?
a. doGet() b. doPost() c. doForm() d. serviceGet()

22. Consider the following code for an HTML form.

<form action=”/servlet/Login”>
<input type=”text” name=”username” value=”enter username”/>
<input type=”submit” name=”sbbutton” value=”signin!..”/>
</form>
Which of the following happens upon pressing the submit button in the above HTML
form?(Choose 2)
a. A request is sent with the HTTP method GET

b. A request is sent with the HTTP method POST

c.The parameter username is the only parameter passed to the web server in the request .

d. The parameters username and sbButton are passed to the web server in the
request URL

e. None of these

23. What will be the output of the following partial servlet code?(Choose 2)

public void doGet(HttpServletRequest request,HttpServletResponse)throws


ServleException,IOException
{
response.setContentType(“text/plain;charset-UTF-8”);
printWriter out=response.getWriter();
out.flust();
( Word to PDF Converter - Unregistered )
http://www.Word-to-PDF-Converter.net
out.close();
System.out.println(response.isCommitted());
Response.setContentType(“illegal/value”);

}
a) An illegalArgumentException is thrown

b) A blank page is returned to the client

c) A 500 error is reported to the client

d) “true” is output on the servlets console

e) false” is output on the server’s console

24. Smith does not want his programmers to use scripting elements in their JSP
pages. Select from the following, the one correct deployment descriptor
programmers can code to achieve the intended result.
a) <jsp-config>
<jsp-property-group>
<url-pattern>jsp</url-pattern>
<scripting-invalid>
true
</scription-invalid>
</jsp-property-group>
</jsp-config>
b) <jsp-config>
<jsp-property-group>
<url-pattern>jsp</url-pattern>
<scripting-invalid>
false
</scription-invalid>
</jsp-property-group>
</jsp-config>
c) <jsp-config>
<jsp-property-group>
<ur-pattern>*.jsp</url-pattern>
<scripting-valid>
true
</scription-valid>
</jsp-property-group>
</jsp-config>
( Word to PDF Converter - Unregistered )
http://www.Word-to-PDF-Converter.net
d) <jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<scripting-invalid>
true
</scription-valid>
</jsp-property-group>
</jsp-config>
25. What will be the result of running the following jsp file taking into account
that the Web server has just been started and this is the first page loaded by
the server?
<html><body>
<%= request.getSession(false).getId() %>
</body></html>
a) It will not compile
b) It will print the sessionId
c) It will produce a NullPointerException as the getSession(false) method's call
returns null, cause no session had been created.
d) It will produce an empty page

26. Consider the following JSP page source:


1) <%@ page import=”java.io.*”%>
2) <html>
3) <body>
4) <%
5) PrintWriter out=response.getWriter();
6) out.write(“P”);
7) %>
8) <%out.write(“Q”);%>
9) </body>
10)</html>
Which two of the following are true statements about the above code?
a) P” will be written to the response, followed by “Q”
b) Only “Q” will be written to the response
c) The page has a compilation error because of a directive syntax error
d) In JSP Technology it is a bad idea to hold the printwriter directly from the
response.
e) The page has a compliation error
( Word to PDF Converter - Unregistered )
http://www.Word-to-PDF-Converter.net
27. The page directive is used to convey information about the page to JSP
container. Which two of the following are legal syntax of page directive?
a) <% page info="test page" %>
b) <%@ page isErrorPage="errorPage.jsp" %>
c) <%@ page isThreadSafe=true %>
d) <%@ page info=”testpage” session=”false”%>
e) <%@ page session= ‘true’%>

28. Consider the following scenario:

An existing JSP page is modified.


The following steps happen when the modified page is requested:
(a) jspInit()
(b) jspDestroy()
(c ) translation
(d) Load the class
(e) _jspService()
(f) Create an Instance
(g) Compile the translated code

Which one of the following options gives the correct sequence in which the above
steps happen?
a) a,b,c,d,e,f,g
b) a,c,g,f,d,e,b
c) c,g,f,d,a,e,b
d) c,g,d,f,a,e,a

29. Consider the following JSP code:

<%@ page language=”java” %>


<%@ page import=”java.util.*” %>
<html>
<body>
<h1>Welcome</h1>
<%! Public void jspInit()
{
System.out.printn(“First half of jspInit()”);
%>
<% new Date()%>
<%! System.out.println(“second half of jspInit()”);
}
%>
</body>
</html>

Which one of the following will be the correct outcome of attempting to access the
above JSP for the second time?

a) Translation error(HTTP response code of 500)


b) Page not found error(HTTP response code of 404)
( Word to PDF Converter - Unregistered )
http://www.Word-to-PDF-Converter.net
c) Web page returned showing a heading and the current date; two lines of output
written to the server log
d) Web page returned showing “First half of jspInit(),” “Second half of jspInit(),” a
heading, and the current date
e) Web page returned showing a heading and the current date

30. Which of the following is NOT a valid design pattern type?


a) Fundamental
b) Presentation
c) Behavioral
d) Accidental

31. Data Access Objects does not decouple client interface from underlying data
access mechanics. State True or False.
a. True b. False
32. When you are learning about design patterns, you notice that the Home
interface of an Enterprise Javabean is actually based on one of the patterns. Which
pattern is the Home Interface of an Enterprise Javabean based on?
a) Singleton
b) Session Façade
c) Business Object
d) Factory Method

33. In distributed applications, lookup and exception handling for remote business
components can be complex.When applications use business components directly,
application code must change to reflect changes in business component APIs.
Which of the following intermediate class solves the above problems?
a) Value Object
b) Business Object
c) Business delegate
d) Façade
34. When remote calls are made on the container provided implementations of the
EJBHome and EJBObject, various transactional and security checks are applied
before the call is actually passed on to the bean instance.
Which of the following Design pattern's task does the container provided
implementations of EJBHome and EJBObject perform?
a. Command b. Adaptor c. Bridge d. Façade e. Decorator

35. Your company has a corporate policy that prohibits storing a customer's credit

card number in any corporate database. However, users have complained that they

do NOT want to re-enter their credit card number for each transaction. Your
( Word to PDF Converter - Unregistered )
http://www.Word-to-PDF-Converter.net
management has decided to use client-side cookies to record the user's credit card

number for 120 days. Furthermore, they also want to protect this information

during transit from the web browser to the web container; so the cookie must only

be transmitted over HTTPS. Which code snippet creates the "creditCard" cookie and

adds it to the out going response to be stored on the user's web browser?

a. 10. Cookie c = new Cookie("creditCard", usersCard);


11. c.setSecure(true);
12. c.setAge(10368000);

b. 10. Cookie c = new Cookie("creditCard", usersCard); 11. c.setHttps(true); 12.


c.setMaxAge(10368000); 13. response.setCookie(c);

c. 10. Cookie c = new Cookie("creditCard", usersCard); 11. c.setSecure(true); 12.


c.setMaxAge(10368000); 13. response.addCookie(c);

d. 10. Cookie c = new Cookie("creditCard", usersCard);


11. c.setHttps(true);
12. c.setAge(10368000);
13. response.addCookie(c);
E. 10. Cookie c = new Cookie("creditCard", usersCard);
11. c.setSecure(true);
12. c.setAge(10368000);
13. response.setCookie(c);

36. A developer has created a web application that includes a servlet for each

use case in the application. These servlets have become rather difficult to maintain

because the request processing methods have become very large. There is also

common processing code in many servlets because these use cases are very

similar. Which two design patterns can be used together to refactor and simplify

this web application? (Choose two correct answers.)

a. Proxy b. View c. Front Controller d. Model-View-Controller

37. A developer is designing a multi-tier web application and discovers a need to

hide the details of establishing and maintaining remote communications from the

client. In addition, because the business and resource tiers are distributed, the
( Word to PDF Converter - Unregistered )
http://www.Word-to-PDF-Converter.net
application needs to minimize the inter-tier network traffic related to servicing

client requests. Which design patterns, working together, address these issues?

a. Front Controller and Transfer Object

b. Front Controller and Service Locator

c. Business Delegate and Transfer Object

d. Model-View-Controller and Intercepting Filter

e. None of these

38. A developer is designing a web application that must verify for each

request:The originating request is from a trusted network.The client has a valid

session.

The client has been authenticated.Which design pattern provides a solution in this

situation?

a. Transfer Object

b. Session Façade

c. Intercepting Filter

d. Model-View-Controller

39. Which of the following combinations (Design Pattern - Usefulness) regarding


Design Patterns are correct? (Choose 2)

a. Business Delegate - Reduces the coupling between presentation-tier clients and


business services
b. Data Access Object - Allows for Multiple Views using the same model
c. MVC - Enables easier migration to different persistence storage implementations
d. Value Object - Reduces Network Traffic
e.. None of these

40. Which one of the following options would initialize a stream for sending text to
a browser?

a) OutputReader out = response.getStream();


b) OuputStream out = response.getStream();
c) PrintWriter out=response.getWriter();
d) ServletWriter out =response.getWriterStream();
e) StreamWriter out = response.getStreamWriter();
( Word to PDF Converter - Unregistered )
http://www.Word-to-PDF-Converter.net
41. Which one of the following is the correct way of retrieving the value of the
"User-Agent" header value from the request from the service method( eg: doPost()
)?
a) String userAgent=request.getParameter("User-Agent");
b) String userAgent=request.getRequestHeader("User-Agent");
c) String userAgent=getServletContext().getInitParameter("User-Agent");
d) String userAgent=request.getHeader(“User_Agent”);

42. When you are learning about design patterns, you notice that the Home
interface of an Enterprise Javabean is actually based on one of the patterns. Which
pattern is the Home Interface of an Enterprise Javabean based on?

a. Singleton b. Session Façade c. Factory method d. None of these

43. Which three of the following methods are declared in HttpServletRequest as


opposed to in ServletRequest?

a. getMethod()
b. getHeader()
c. getCookies()
d. getInputStream
e. getParameterName()

44. Consider the following servlet code:

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MyFirstServlet extends HttpServlet
{
public void service(HttpServletRequest req, HttpServletResponse res) throws
ServletException, IOException
{
res.setContentType("text/html");
}

public void doGet(HttpServletRequest req, HttpServletResponse res) throws


ServletException, IOException
{
res.getWriter().println("This is doGet!");
}

public void doPost(HttpServletRequest req, HttpServletResponse res) throws


ServletException, IOException
( Word to PDF Converter - Unregistered )
http://www.Word-to-PDF-Converter.net
{
res.getWriter().println("This is doPost!");
}
}

This servlet is executed by clicking on a submit button of a form in a web page:


<form action="/MyFirstServlet" method=POST>
<input type=submit>
</form>

Predict the output.


Select one answer from the following.
a) This is doPost
b) This is doGet
c) "This is doPost" as well as "This is doGet"
d) It will not print anything
e) “This is doGet!” is printed
45. What will happen when you attempt to compile and run the following code
(assuming menu.jsp is available)?

package com.evaluvate;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class ReqD extends HttpServlet {


protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ServletContext sc = this.getServletContext();
RequestDispatcher dis = sc.getRequestDispatcher("menu.jsp");
if (dis != null){
dis.include(request, response);
}
PrintWriter out = response.getWriter();
out.print("Output after menu.jsp");
}
}

Select one answer from the following.

a) Compilation error, the this object is not available within doGet


b) Compilation success and output of the contents of menu.jsp followed by "output after
menu.jsp"
c) Compilation success and output of the contents of menu.jsp only
d) Compilation Success but runtime error
( Word to PDF Converter - Unregistered )
http://www.Word-to-PDF-Converter.net

*********ALL THE BEST*************

Вам также может понравиться