1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | public class SelectionSort { /** * @Author Chandrasekhara Kota */ public static void main(String[] args) { int arr[]={9,1,8,5,7,-1,6,0,2,2718}; int sortedArr[]=selectionSort(arr); for (int i = 0; i <sortedArr.length; i++) { System.out.println(sortedArr[i]); } } private static int[] selectionSort(int[] arr) { int minIndex, tmp; int n = arr.length; for (int i = 0; i < n - 1; i++) { minIndex = i; for (int j = i + 1; j < n; j++) if (arr[j] < arr[minIndex]) minIndex = j; if (minIndex != i) { tmp = arr[i]; arr[i] = arr[minIndex]; arr[minIndex] = tmp; } } return arr; } } |
It's all about Java development. A place mainly for java programmers.
Tuesday, 20 December 2011
SelectionSort
Monday, 19 December 2011
BubbleSort
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | public class BubbleSort { /** * @Author : Chandrasekhara Kota * @Date : 17-December-2011 */ public static void main(String[] args) { // TODO Auto-generated method stub int num[]={4,1,9,5,2,8,10}; for(int i=0;i<num.length;i++) { for(int y=0;y<num.length-1;y++) { if(num[y]>num[y+1]) { int temp=num[y+1]; num[y+1]=num[y]; num[y]=temp; } } } System.out.println("Sorted Data is :"); for(int i=0;i<num.length;i++) { System.out.print(" "+num[i]); } } } |
Saturday, 17 December 2011
SCWCD Questions 261 - 276
QUESTION NO: 261
Which three are true about servlet filters? (Choose three.)
A. A filter must implement the destroy method.
B. A filter must implement the doFilter method.
C. A servlet may have multiple filters associated with it.
D. A servlet that is to have a filter applied to it must implement the javax.servlet.FilterChain
interface.
E. A filter that is part of a filter chain passes control to the next filter in the chain by invoking the
FilterChain.forward method.
F. For each <filter> element in the web application deployment descriptor, multiple instances of a
filter may be created by the web container.
Answer: A,B,C
QUESTION NO: 262 DRAG DROP
Click the Task button.
Place the XML elements in the web application deployment descriptor solution to configure a
servlet context event listener named com.example.MyListener.
Answer:
Explanation:
QUESTION NO: 263
Which is true about the web container request processing model?
A. The init method on a filter is called the first time a servlet mapped to that filter is invoked.
B. A filter defined for a servlet must always forward control to the next resource in the filter chain.
C. Filters associated with a named servlet are applied in the order they appear in the web
application deployment descriptor file.
D. If the init method on a filter throws an UnavailableException, then the container will make no
further attempt to execute it.
Answer: C
QUESTION NO: 264
Your IT department is building a lightweight Front Controller servlet that invokes an application
logic object with the interface:
public interface ApplicationController {
public String invoke(HttpServletRequest request)
}
The return value of this method indicates a symbolic name of the next view. From this name, the
Front Controller servlet looks up the JSP URL in a configuration table. This URL might be an
absolute path or a path relative to the current request. Next, the Front Controller servlet must send
the request to this JSP to generate the view. Assume that the servlet variable request is assigned
the current HttpServletRequest object and the variable context is assigned the webapp's
ServletContext.
Which code snippet of the Front Controller servlet accomplishes this goal?
A. Dispatcher view
= context.getDispatcher(viewURL);
view.forwardRequest(request, response);
B. Dispatcher view
= request.getDispatcher(viewURL);
view.forwardRequest(request, response);
C. RequestDispatcher view
= context.getRequestDispatcher(viewURL);
view.forward(request, response);
D. RequestDispatcher view
= request.getRequestDispatcher(viewURL);
view.forward(request, response);
Answer: D
QUESTION NO: 265
Given that a web application consists of two HttpServlet classes, ServletA and ServletB, and the
ServletA.service method:
20. String key = "com.example.data";
21. session.setAttribute(key, "Hello");
22. Object value = session.getAttribute(key);
23.
Assume session is an HttpSession, and is not referenced anywhere else in ServletA.
Which two changes, taken together, ensure that value is equal to "Hello" on line 23? (Choose
two.)
A. ensure that the ServletB.service method is synchronized
B. ensure that the ServletA.service method is synchronized
C. ensure that ServletB synchronizes on the session object when setting session attributes
D. enclose lines 21-22 in a synchronized block:
synchronized(this) {
session.setAttribute(key, "Hello");
value = session.getAttribute(key);
}
E. enclose lines 21-22 in a synchronized block:
synchronized(session) {
session.setAttribute(key, "Hello");
value = session.getAttribute(key);
}
Answer: C,E
QUESTION NO: 266
Which retrieves all cookies sent in a given HttpServletRequest request?
A. request.getCookies()
B. request.getAttributes()
C. request.getSession().getCookies()
D. request.getSession().getAttributes()
Answer: A
QUESTION NO: 267
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 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);
13. response.addCookie(c);
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);
Answer: C
QUESTION NO: 268 DRAG DROP
Click the Task button.
Given a servlet mapped to /control, place the correct URI segment returned as a String on the
corresponding HttpServletRequest method call for the URI: /myapp/control/processorder.
Answer:
QUESTION NO: 269
A web browser need NOT always perform a complete request for a particular page that it suspects
might NOT have changed. The HTTP specification provides a mechanism for the browser to
retrieve only a partial response from the web server; this response includes information, such as
the Last-Modified date but NOT the body of the page. Which HTTP method will the browser use to
retrieve such a partial response?
A. GET
B. ASK
C. SEND
D. HEAD
E. TRACE
F. OPTIONS
Answer: D
QUESTION NO: 270
You are creating a servlet that generates stock market graphs. You want to provide the web
browser with precise information about the amount of data being sent in the response stream.
Which two HttpServletResponse methods will you use to provide this information? (Choose two.)
A. response.setLength(numberOfBytes);
B. response.setContentLength(numberOfBytes);
C. response.setHeader("Length", numberOfBytes);
D. response.setIntHeader("Length", numberOfBytes);
E. response.setHeader("Content-Length", numberOfBytes);
F. response.setIntHeader("Content-Length", numberOfBytes);
Answer: B,F
QUESTION NO: 271
Which two prevent a servlet from handling requests? (Choose two.)
A. The servlet's init method returns a non-zero status.
B. The servlet's init method throws a ServletException.
C. The servlet's init method sets the ServletResponse's content length to 0.
D. The servlet's init method sets the ServletResponse's content type to null.
E. The servlet's init method does NOT return within a time period defined by the servlet container.
Answer: B,E
QUESTION NO: 272
A web application allows the HTML title banner to be set using a servlet context initialization
parameter called titleStr. Which two properly set the title in this scenario? (Choose two.)
A. <title>${titleStr}</title>
B. <title>${initParam.titleStr}</title>
C. <title>${params[0].titleStr}</title>
D. <title>${paramValues.titleStr}</title>
E. <title>${initParam['titleStr']}</title>
F. <title>${servletParams.titleStr}</title>
G. <title>${request.get("titleStr")}</title>
Answer: B,E
QUESTION NO: 273
You are building a dating service web site. Part of the form to submit a client's profile is a group of
radio buttons for the person's hobbies:
20. <input type='radio' name='hobbyEnum' value='HIKING'>Hiking <br>
21. <input type='radio' name='hobbyEnum' value='SKIING'>Skiing <br>
22. <input type='radio' name='hobbyEnum' value='SCUBA'>SCUBA Diving
23. <!-- and more options -->
After the user submits this form, a confirmation screen is displayed with these hobbies listed.
Assume that an application-scoped variable, hobbies, holds a map between the Hobby
enumerated type and the display name.
Which EL code snippet will display Nth element of the user's selected hobbies?
A. ${hobbies[hobbyEnum[N]}
B. ${hobbies[paramValues.hobbyEnum[N]]}
C. ${hobbies[paramValues@'hobbyEnum'@N]}
D. ${hobbies.get(paramValues.hobbyEnum[N])}
E. ${hobbies[paramValues.hobbyEnum.get(N)]}
Answer: B
QUESTION NO: 274
Given a web application in which the request parameter productID contains a product identifier.
Which two EL expressions evaluate the value of the productID? (Choose two.)
A. ${productID}
B. ${param.productID}
C. ${params.productID}
D. ${params.productID[1]}
E. ${paramValues.productID}
F. ${paramValues.productID[0]}
G. ${pageContext.request.productID}
Answer: B,F
QUESTION NO: 275
You are building a web application with a scheduling component. On the JSP, you need to show
the current date, the date of the previous week, and the date of the next week. To help you
present this information, you have created the following EL functions in the 'd' namespace:
name: curDate; signature: java.util.Date currentDate()
name: addWeek; signature: java.util.Date addWeek(java.util.Date, int)
name: dateString; signature: java.util.String getDateString(java.util.Date)
Which EL code snippet will generate the string for the previous week?
A. ${d:dateString(addWeek(curDate(), -1))}
B. ${d:dateString[addWeek[curDate[], -1]]}
C. ${d:dateString[d:addWeek[d:curDate[], -1]]}
D. ${d:dateString(d:addWeek(d:curDate(), -1))}
Answer: D
QUESTION NO: 276
You are building a dating web site. The client's date of birth is collected along with lots of other
information. The Person class has a derived method, getAge():int, which returns the person's age
calculated from the date of birth and today's date. In one of your JSPs you need to print a special
message to clients within the age group of 25 through 35. Which two EL code snippets will return
true for this condition? (Choose two.)
A. ${client.age in [25,35]}
B. ${client.age between [25,35]}
C. ${client.age between 25 and 35}
D. ${client.age <= 35 && client.age >= 25}
E. ${client.age le 35 and client.age ge 25}
F. ${not client.age > 35 && client.age < 25}
Answer: D,E
SCWCD Questions 251 - 260
QUESTION NO: 251
Which two are true about the JSTL core iteration custom tags? (Choose two.)
A. It may iterate over arrays, collections, maps, and strings.
B. The body of the tag may contain EL code, but not scripting code.
C. When looping over collections, a loop status object may be used in the tag body.
D. It may iterate over a map, but only the key of the mapping may be used in the tag body.
E. When looping over integers (for example begin='1' end='10'), a loop status object may not be
used in the tag body.
Answer: A,C
QUESTION NO: 252
Which two are valid and equivalent? (Choose two.)
A. <%! int i; %>
B. <%= int i; %>
C. <jsp:expr>int i;</jsp:expr>
D. <jsp:scriptlet>int i;</jsp:scriptlet>
E. <jsp:declaration>int i;</jsp:declaration>
Answer: A,E
QUESTION NO: 253
The JSP developer wants a comment to be visible in the final output to the browser. Which
comment style needs to be used in a JSP page?
A. <!-- this is a comment -->
B. <% // this is a comment %>
C. <%-- this is a comment --%>
D. <% /** this is a comment **/ %>
Answer: A
QUESTION NO: 254
Which is a benefit of precompiling a JSP page?
A. It avoids initialization on the first request.
B. It provides the ability to debug runtime errors in the application.
C. It provides better performance on the first request for the JSP page.
D. It avoids execution of the _jspService method on the first request.
Answer: C
QUESTION NO: 255
Given tutorial.jsp:
2. <h1>EL Tutorial</h1>
3. <h2>Example 1</h2>
4. <p>
5. Dear ${my:nickname(user)}
6. </p>
Which, when added to the web application deployment descriptor, ensures that line 5 is included
verbatim in the JSP output?
A. <jsp-config>
<url-pattern>*.jsp</url-pattern>
<el-ignored>true</el-ignored>
</jsp-config>
B. <jsp-config>
<url-pattern>*.jsp</url-pattern>
<isELIgnored>true</isELIgnored>
</jsp-config>
C. <jsp-config>
<jsp-property-group>
<el-ignored>*.jsp</el-ignored>
</jsp-property-group>
</jsp-config>
D. <jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<el-ignored>true</el-ignored>
</jsp-property-group>
</jsp-config>
E. <jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<isElIgnored>true</isElIgnored>
</jsp-property-group>
</jsp-config>
Answer: D
QUESTION NO: 256
In a JSP-centric web application, you need to create a catalog browsing JSP page. The catalog is
stored as a List object in the catalog attribute of the webapp's ServletContext object. Which
scriptlet code snippet gives you access to the catalog object?
A. <% List catalog = config.getAttribute("catalog"); %>
B. <% List catalog = context.getAttribute("catalog"); %>
C. <% List catalog = application.getAttribute("catalog"); %>
D. <% List catalog = servletContext.getAttribute("catalog"); %>
Answer: C
QUESTION NO: 257
You are building your own layout mechanism by including dynamic content for the page's header
and footer sections. The footer is always static, but the header generates the <title> tag that
requires the page name to be specified dynamically when the header is imported. Which JSP code
snippet performs the import of the header content?
A. <jsp:include page='/WEB-INF/jsp/header.jsp'>
<jsp:param name='pageName' value='Welcome Page' />
</jsp:include>
B. <jsp:import page='/WEB-INF/jsp/header.jsp'>
<jsp:param name='pageName' value='Welcome Page' />
</jsp:import>
C. <jsp:include page='/WEB-INF/jsp/header.jsp'>
<jsp:attribute name='pageName' value='Welcome Page' />
</jsp:include>
D. <jsp:import page='/WEB-INF/jsp/header.jsp'>
<jsp:attribute name='pageName' value='Welcome Page' />
</jsp:import>
Answer: A
QUESTION NO: 258
Which ensures that a JSP response is of type "text/plain"?
A. <%@ page mimeType="text/plain" %>
B. <%@ page contentType="text/plain" %>
C. <%@ page pageEncoding="text/plain" %>
D. <%@ page contentEncoding="text/plain" %>
E. <% response.setEncoding("text/plain"); %>
F. <% response.setMimeType("text/plain"); %>
Answer: B
QUESTION NO: 259
Your web application uses a simple architecture in which servlets handle requests and then
forward to a JSP using a request dispatcher. You need to pass information calculated in the
servlet to the JSP for view generation. This information must NOT be accessible to any other
servlet, JSP or session in the webapp. Which two techniques can you use to accomplish this goal?
(Choose two.)
A. Add attributes to the session object.
B. Add attributes on the request object.
C. Add parameters to the request object.
D. Use the pageContext object to add request attributes.
E. Add parameters to the JSP's URL when generating the request dispatcher.
Answer: B,E
QUESTION NO: 260
All of your JSPs need to have a link that permits users to email the web master. This web
application is licensed to many small businesses, each of which have a different email address for
the web master. You have decided to use a context parameter that you specify in the deployment
descriptor, like this:
42. <context-param>
43. <param-name>webmasterEmail</param-name>
44. <param-value>master@example.com</param-value>
45. </context-param>
Which JSP code snippet creates this email link?
A. <a href='mailto:${contextParam.webmasterEmail}'>contact us</a>
B. <a href='mailto:${applicationScope.webmasterEmail}'>contact us</a>
C. <a href='mailto:${contextInitParam.webmasterEmail}'>contact us</a>
D. <a href='mailto:${initParam.webmasterEmail}'>contact us</a>
Answer: D
SCWCD Questions 241- 250
QUESTION NO: 241
Which interface must a session attribute implement if it needs to be notified when a web container
persists a session?
A. javax.servlet.http.HttpSessionListener
B. javax.servlet.http.HttpSessionBindingListener
C. javax.servlet.http.HttpSessionAttributeListener
D. javax.servlet.http.HttpSessionActivationListener
Answer: D
QUESTION NO: 242
What is the purpose of session management?
A. To manage the user's login and logout activities.
B. To store information on the client-side between HTTP requests.
C. To store information on the server-side between HTTP requests.
D. To tell the web container to keep the HTTP connection alive so it can make subsequent
requests without the delay of making the TCP connection.
Answer: C
QUESTION NO: 243
You need to store a Java long primitive attribute, called customerOID, into the session scope.
Which two code snippets allow you to insert this value into the session? (Choose two.)
A. long customerOID = 47L;
session.setAttribute("customerOID", new Long(customerOID));
B. long customerOID = 47L;
session.setLongAttribute("customerOID", new Long(customerOID));
C. long customerOID = 47L;
session.setAttribute("customerOID", customerOID);
D. long customerOID = 47L;
session.setNumericAttribute("customerOID", new Long(customerOID));
E. long customerOID = 47L;
session.setLongAttribute("customerOID", customerOID);
F. long customerOID = 47L;
session.setNumericAttribute("customerOID", customerOID);
Answer: A,C
QUESTION NO: 244
Click the Exhibit button.
Assuming the tag library in the exhibit is imported with the prefix forum, which custom tag
invocation produces a translation error in a JSP page?
A. <forum:message from="My Name" subject="My Subject" />
B. <forum:message subject="My Subject">
My message body.
</forum:message>
C. <forum:message from="My Name" subject="${param.subject}">
${param.body}
</forum:message>
D. <forum:message from="My Name" subject="My Subject">
<%= request.getParameter( "body" ) %>
</forum:message>
E. <forum:message from="My Name"
subject="<%= request.getParameter( "subject" ) %>">
My message body.
</forum:message>
Answer: D
QUESTION NO: 245
Given in a single JSP page:
<%@ taglib prefix='java' uri='myTags' %>
<%@ taglib prefix='JAVA' uri='moreTags' %>
Which two are true? (Choose two.)
A. The prefix 'java' is reserved.
B. The URI 'myTags' must be properly mapped to a TLD file by the web container.
C. A translation error occurs because the prefix is considered identical by the web container.
D. For the tag usage <java:tag1/>, the tag1 must be unique in the union of tag names in 'myTags'
and 'moreTags'.
Answer: A,B
QUESTION NO: 246
In a JSP-centric shopping cart application, you need to move a client's home address of the
Customer object into the shipping address of the Order object. The address data is stored in a
value object class called Address with properties for: street address, city, province, country, and
postal code. Which two JSP code snippets can be used to accomplish this goal? (Choose two.)
A. <c:set var='order' property='shipAddress'
value='${client.homeAddress}' />
B. <c:set target='${order}' property='shipAddress'
value='${client.homeAddress}' />
C. <jsp:setProperty name='${order}' property='shipAddress'
value='${client.homeAddress}' />
D. <c:set var='order' property='shipAddress'>
<jsp:getProperty name='client' property='homeAddress' />
</c:store>
E. <c:set target='${order}' property='shipAddress'>
<jsp:getProperty name='client' property='homeAddress' />
</c:set>
F. <c:setProperty name='${order}' property='shipAddress'>
<jsp:getProperty name='client' property='homeAddress' />
</c:setProperty>
Answer: B,E
QUESTION NO: 247
Given that a scoped attribute cart exists only in a user's session, which two, taken independently,
ensure the scoped attribute cart no longer exists? (Choose two.)
A. ${cart = null}
B. <c:remove var="cart" />
C. <c:remove var="${cart}" />
D. <c:remove var="cart" scope="session" />
E. <c:remove scope="session">cart</c:remove>
F. <c:remove var="${cart}" scope="session" />
G. <c:remove scope="session">${cart}</c:remove>
Answer: B,D
QUESTION NO: 248
In which three directories, relative to a web application's root, may a tag library descriptor file
reside when deployed directly into a web application? (Choose three.)
A. /WEB-INF
B. /META-INF
C. /WEB-INF/tlds
D. /META-INF/tlds
E. /WEB-INF/resources
F. /META-INF/resources
Answer: A,C,E
QUESTION NO: 249
You have been contracted to create a web site for a free dating service. One feature is the ability
for one client to send a message to another client, which is displayed in the latter client's private
page. Your contract explicitly states that security is a high priority. Therefore, you need to prevent
cross-site hacking in which one user inserts JavaScript code that is then rendered and invoked
when another user views that content. Which two JSTL code snippets will prevent cross-site
hacking in the scenario above? (Choose two.)
A. <c:out>${message}</c:out>
B. <c:out value='${message}' />
C. <c:out value='${message}' escapeXml='true' />
D. <c:out eliminateXml='true'>${message}</c:out>
E. <c:out value='${message}' eliminateXml='true' />
Answer: B,C
QUESTION NO: 250
A custom tag is defined to take three attributes. Which two correctly invoke the tag within a JSP
page? (Choose two.)
A. <prefix:myTag a="foo" b="bar" c="baz" />
B. <prefix:myTag attributes={"foo","bar","baz"} />
C. <prefix:myTag jsp:attribute a="foo" b="bar" c="baz" />
D. <prefix:myTag>
<jsp:attribute a:foo b:bar c:baz />
</prefix:myTag>
E. <prefix:myTag>
<jsp:attribute ${"foo", "bar", "baz"} />
</prefix:myTag>
F. <prefix:myTag>
<jsp:attribute a="foo" b="bar" c="baz"/>
</prefix:myTag>
G. <prefix:myTag>
<jsp:attribute name="a">foo</jsp:attribute>
<jsp:attribute name="b">bar</jsp:attribute>
<jsp:attribute name="c">baz</jsp:attribute>
</prefix:myTag>
Answer: A,G
SCWCD Questions 231- 240
QUESTION NO: 231
Which two statements are true about the security-related tags in a valid Java EE deployment
descriptor? (Choose two.)
A. Every <security-constraint> tag must have at least one <http-method> tag.
B. A <security-constraint> tag can have many <web-resource-collection> tags.
C. A given <auth-constraint> tag can apply to only one <web-resource-collection> tag.
D. A given <web-resource-collection> tag can contain from zero to many <url-pattern> tags.
E. It is possible to construct a valid <security-constraint> tag such that, for a given resource, no
user roles can access that resource.
Answer: B,E
QUESTION NO: 232
Which element of a web application deployment descriptor <security-constraint> element is
required?
A. <realm-name>
B. <auth-method>
C. <security-role>
D. <transport-guarantee>
E. <web-resource-collection>
Answer: E
QUESTION NO: 233
Which two are required elements for the <web-resource-collection> element of a web application
deployment descriptor? (Choose two.)
A. <realm-name>
B. <url-pattern>
C. <description>
D. <web-resource-name>
E. <transport-guarantee>
Answer: B,D
QUESTION NO: 234
Given:
3. class MyServlet extends HttpServlet {
4. public void doPut(HttpServletRequest req,
HttpServletResponse resp)
throws ServletException, IOException {
5. // servlet code here
...
26. }
27. }
If the DD contains a single security constraint associated with MyServlet and its only <httpmethod>
tags and <auth-constraint> tags are:
<http-method>GET</http-method>
<http-method>PUT</http-method>
<auth-constraint>Admin</auth-constraint>
Which four requests would be allowed by the container? (Choose four.)
A. A user whose role is Admin can perform a PUT.
B. A user whose role is Admin can perform a GET.
C. A user whose role is Admin can perform a POST.
D. A user whose role is Member can perform a PUT.
E. A user whose role is Member can perform a POST.
F. A user whose role is Member can perform a GET.
Answer: A,B,C,E
QUESTION NO: 235
What is true about Java EE authentication mechanisms?
A. If your deployment descriptor correctly declares an authentication type of CLIENT_CERT, your
users must have a certificate from an official source before they can use your application.
B. If your deployment descriptor correctly declares an authentication type of BASIC, the container
automatically requests a user name and password whenever a user starts a new session.
C. If you want your web application to support the widest possible array of browsers, and you want
to perform authentication, the best choice of Java EE authentication mechanisms is DIGEST.
D. To use Java EE FORM authentication, you must declare two HTML files in your deployment
descriptor, and you must use a predefined action in the HTML file that handles your user's login.
Answer: D
QUESTION NO: 236
Which two statements are true about using the isUserInRole method to implement security in a
Java EE application? (Choose two.)
A. It can be invoked only from the doGet or doPost methods.
B. It can be used independently of the getRemoteUser method.
C. Can return "true" even when its argument is NOT defined as a valid role name in the
deployment descriptor.
D. Using the isUserInRole method overrides any declarative authentication related to the method
in which it is invoked.
E. Using the isUserInRole method overrides any declarative authorization related to the method in
which it is invoked.
Answer: B,C
QUESTION NO: 237
Given an HttpServletRequest request and an HttpServletResponse response:
41. HttpSession session = null;
42. // insert code here
43. if(session == null) {
44. // do something if session does not exist
45. } else {
46. // do something if session exists
47. }
To implement the design intent, which statement must be inserted at line 42?
A. session = response.getSession();
B. session = request.getSession();
C. session = request.getSession(true);
D. session = request.getSession(false);
E. session = request.getSession("jsessionid");
Answer: D
QUESTION NO: 238
You need to store a floating point number, called Tsquare, in the session scope. Which two code
snippets allow you to retrieve this value? (Choose two.)
A. float Tsquare = session.getFloatAttribute("Tsquare");
B. float Tsquare = (Float) session.getAttribute("Tsquare");
C. float Tsquare = (float) session.getNumericAttribute("Tsquare");
D. float Tsquare = ((Float) session.getAttribute.("Tsquare")).floatValue();
E. float Tsquare = ((Float) session.getFloatAttribute.("Tsquare")).floatValue;
F. float Tsquare = ((Float) session.getNumericAttribute.("Tsquare")).floatValue;
Answer: B,D
QUESTION NO: 239
A web application uses the HttpSession mechanism to determine if a user is "logged in." When a
user supplies a valid user name and password, an HttpSession is created for that user.
The user has access to the application for only 15 minutes after logging in. The code must
determine how long the user has been logged in, and if this time is greater than 15 minutes, must
destroy the HttpSession.
Which method in HttpSession is used to accomplish this?
A. getCreationTime
B. invalidateAfter
C. getLastAccessedTime
D. getMaxInactiveInterval
Answer: A
QUESTION NO: 240
Which method must be used to encode a URL passed as an argument to
HttpServletResponse.sendRedirect when using URL rewriting for session tracking?
A. ServletResponse.encodeURL
B. HttpServletResponse.encodeURL
C. ServletResponse.encodeRedirectURL
D. HttpServletResponse.encodeRedirectURL
Answer: D
SCWCD Questions 221 - 230
QUESTION NO: 221
Which defines the welcome files in a web application deployment descriptor?
A. <welcome>
<welcome-file>/welcome.jsp</welcome-file>
</welcome>
<welcome>
<welcome-file>/index.html</welcome-file>
</welcome>
B. <welcome-file-list>
<welcome-file>welcome.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
C. <welcome>
<welcome-file>welcome.jsp</welcome-file>
</welcome>
<welcome>
<welcome-file>index.html</welcome-file>
</welcome>
D. <welcome-file-list>
<welcome-file>/welcome.jsp</welcome-file>
<welcome-file>/index.html</welcome-file>
</welcome-file-list>
E. <welcome>
<welcome-file>
<welcome-name>Welcome</welcome-name>
<location>welcome.jsp</location>
</welcome-file>
<welcome-file>
<welcome-name>Index</welcome-name>
<location>index.html</location>
</welcome-file>
</welcome>
Answer: B
QUESTION NO: 222
Click the Exhibit button.
Assume the product attribute does NOT yet exist in any scope.
Which two create an instance of com.example.Product and initialize the name and price properties
to the name and price request parameters? (Choose two.)
A. <jsp:useBean id="product" class="com.example.Product" />
<jsp:setProperty name="product" property="*" />
B. <jsp:useBean id="product" class="com.example.Product" />
<% product.setName( request.getParameter( "name" ) ); %>
<% product.setPrice( request.getParameter( "price" ) ); %>
C. <jsp:useBean id="product" class="com.example.Product" />
<jsp:setProperty name="product" property="name"
value="${param.name}" />
<jsp:setProperty name="product" property="price"
value="${param.price}" />
D. <jsp:useBean id="product" class="com.example.Product">
<jsp:setProperty name="product" property="name"
value="${name}" />
<jsp:setProperty name="product" property="price"
value="${price}" />
</jsp:useBean>
Answer: A,C
QUESTION NO: 223
Click the Exhibit button.
A session-scoped attribute, product, is stored by a servlet. That servlet then forwards to a JSP
page. This attribute holds an instance of the com.example.Product class with a name property of
"The Matrix" and price property of 39.95.
Given the JSP page code snippet:
1. <jsp:useBean id='product' class='com.example.Product'>
2. <jsp:setProperty name='product' property='price' value='49.95'/>
3. </jsp:useBean>
4. <%= product.getName() %> costs <%= product.getPrice() %>
What is the response output of this JSP page code snippet?
A. Default costs 0.0
B. Default costs 49.95
C. Default costs 39.95
D. The Matrix costs 0.0
E. The Matrix costs 49.95
F. The Matrix costs 39.95
Answer: B
QUESTION NO: 224
Click the Exhibit button.
A servlet sets a session-scoped attribute product with an instance of com.example.Product and
forwards to a JSP.
Which two output the name of the product in the response? (Choose two.)
A. ${product.name}
B. <jsp:getProperty name="product" property="name" />
C. <jsp:useBean id="com.example.Product" />
<%= product.getName() %>
D. <jsp:getProperty name="product" class="com.example.Product"
property="name" />
E. <jsp:useBean id="product" type="com.example.Product">
<%= product.getName() %>
</jsp:useBean>
Answer: A,B
QUESTION NO: 225
You have built your own light-weight templating mechanism. Your servlets, which handle each
request, dispatch the request to one of a small set of template JSP pages. Each template JSP
controls the layout of the view by inserting the header, body, and footer elements into specific
locations within the template page. The URLs for these three elements are stored in requestscoped
variables called, headerURL, bodyURL, and footerURL, respectively. These attribute
names are never used for other purposes. Which JSP code snippet should be used in the
template JSP to insert the JSP content for the body of the page?
A. <jsp:insert page='${bodyURL}' />
B. <jsp:insert file='${bodyURL}' />
C. <jsp:include page='${bodyURL}' />
D. <jsp:include file='${bodyURL}' />
E. <jsp:insert page='<%= bodyURL %>' />
F. <jsp:include page='<%= bodyURL %>' />
Answer: C
QUESTION NO: 226
Given:
3. public class MyTagHandler extends TagSupport {
4. public int doStartTag() {
5. // insert code here
6. // return an int
7. }
8. // more code here
...
18. }
There is a single attribute foo in the session scope.
Which three code fragments, inserted independently at line 5, return the value of the attribute?
(Choose three.)
A. Object o = pageContext.getAttribute("foo");
B. Object o = pageContext.findAttribute("foo");
C. Object o = pageContext.getAttribute("foo",
PageContext.SESSION_SCOPE);
D. HttpSession s = pageContext.getSession();
Object o = s.getAttribute("foo");
E. HttpServletRequest r = pageContext.getRequest();
Object o = r.getAttribute("foo");
Answer: B,C,D
QUESTION NO: 227
You are creating a content management system (CMS) with a web application front-end. The JSP
that displays a given document in the CMS has the following general structure:
1. <%-- tag declaration --%>
2. <t:document>
...
11. <t:paragraph>... <t:citation docID='xyz' /> ...</t:paragraph>
...
99. </t:document>
The citation tag must store information in the document tag for the document tag to generate a
reference section at the end of the generated web page.
The document tag handler follows the Classic tag model and the citation tag handler follows the
Simple tag model. Furthermore, the citation tag could also be embedded in other custom tags that
could have either the Classic or Simple tag handler model.
Which tag handler method allows the citation tag to access the document tag?
A. public void doTag() {
JspTag docTag = findAncestorWithClass(this, DocumentTag.class);
((DocumentTag)docTag).addCitation(this.docID);
}
B. public void doStartTag() {
JspTag docTag = findAncestorWithClass(this, DocumentTag.class);
((DocumentTag)docTag).addCitation(this.docID);
}
C. public void doTag() {
Tag docTag = findAncestor(this, DocumentTag.class);
((DocumentTag)docTag).addCitation(this.docID);
}
D. public void doStartTag() {
Tag docTag = findAncestor(this, DocumentTag.class);
((DocumentTag)docTag).addCitation(this.docID);
}
Answer: A
QUESTION NO: 228
Given:
6. <myTag:foo bar='42'>
7. <%="processing" %>
8. </myTag:foo>
and a custom tag handler for foo which extends TagSupport.
Which two are true about the tag handler referenced by foo? (Choose two.)
A. The doStartTag method is called once.
B. The doAfterBody method is NOT called.
C. The EVAL_PAGE constant is a valid return value for the doEndTag method.
D. The SKIP_PAGE constant is a valid return value for the doStartTag method.
E. The EVAL_BODY_BUFFERED constant is a valid return value for the doStartTag method.
Answer: A,C
QUESTION NO: 229
Which two are true concerning the objects available to developers creating tag files? (Choose
two.)
A. The session object must be declared explicitly.
B. The request and response objects are available implicitly.
C. The output stream is available through the implicit outStream object.
D. The servlet context is available through the implicit servletContext object.
E. The JspContext for the tag file is available through the implicit jspContext object.
Answer: B,E
QUESTION NO: 230
You web application uses a lot of Java enumerated types in the domain model of the application.
Built into each enum type is a method, getDisplay(), which returns a localized, user-oriented string.
There are many uses for presenting enums within the web application, so your manager has
asked you to create a custom tag that iterates over the set of enum values and processes the
body of the tag once for each value; setting the value into a page-scoped attribute called,
enumValue. Here is an example of how this tag is used:
10. <select name='season'>
11. <t:everyEnum type='com.example.Season'>
12. <option value='${enumValue}'>${enumValue.display}</option>
13. </t:everyEnum>
14. </select>
You have decided to use the Simple tag model to create this tag handler.
Which tag handler method will accomplish this goal?
A. public void doTag() throw JspException {
try {
for ( Enum value : getEnumValues() ) {
pageContext.setAttribute("enumValue", value);
getJspBody().invoke(getOut());
}
} (Exception e) { throw new JspException(e); }
}
B. public void doTag() throw JspException {
try {
for ( Enum value : getEnumValues() ) {
getJspContext().setAttribute("enumValue", value);
getJspBody().invoke(null);
}
} (Exception e) { throw new JspException(e); }
}
C. public void doTag() throw JspException {
try {
for ( Enum value : getEnumValues() ) {
getJspContext().setAttribute("enumValue", value);
getJspBody().invoke(getJspContext().getWriter());
}
} (Exception e) { throw new JspException(e); }
}
D. public void doTag() throw JspException {
try {
for ( Enum value : getEnumValues() ) {
pageContext.setAttribute("enumValue", value);
getJspBody().invoke(getJspContext().getWriter());
}
} (Exception e) { throw new JspException(e); }
}
Answer: B
SCWCD Questions 211 - 220
QUESTION NO: 211
A developer is designing the presentation tier for a web application that relies on a complex
session bean. The session bean is still being developed and the APIs for it are NOT finalized. Any
changes to the session bean API directly impacts the development of the presentation tier. Which
design pattern provides a means to manage the uncertainty in the API?
A. View Helper
B. Front Controller
C. Composite View
D. Intercepting Filter
E. Business Delegate
F. Chain of Responsibility
Answer: E
QUESTION NO: 212
A developer is designing a multi-tier web application and discovers a need to log each incoming
client request. Which two patterns, taken independently, provide a solution for this problem?
(Choose two.)
A. Transfer Object
B. Service Locator
C. Front Controller
D. Intercepting Filter
E. Business Delegate
F. Model-View-Controller
Answer: C,D
QUESTION NO: 213
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 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. Business Delegate and Intercepting Filter
E. Model-View-Controller and Intercepting Filter
Answer: C
QUESTION NO: 214 DRAG DROP
Click the Task button.
Place the servlet name onto every request URL, relative to the web application context root, that
will invoke that servlet. Every request URL must be filled.
Answer:
QUESTION NO: 215
Given a portion of a valid Java EE web application's directory structure:
MyApp
|
|-- File1.html
|
|-- Directory1
| |-- File2.html |
|-- META-INF
|-- File3.html
You want to know whether File1.html, File2.html, and/or File3.html will be directly accessible by
your web client's browsers.
Which statement is true?
A. All three files are directly accessible.
B. Only File1.html is directly accessible.
C. Only File2.html is directly accessible.
D. Only File3.html is directly accessible.
E. Only File1.html and File2.html are directly accessible.
F. Only File1.html and File3.html are directly accessible.
G. Only File2.html and File3.html are directly accessible.
Answer: E
QUESTION NO: 216
Which three are described in the standard web application deployment descriptor? (Choose
three.)
A. session configuration
B. MIME type mappings
C. context root for the application
D. servlet instance pool configuration
E. web container default port bindings
F. ServletContext initialization parameters
Answer: A,B,F
QUESTION NO: 217
You have created a servlet that generates weather maps. The data for these maps is calculated
by a remote host. The IP address of this host is usually stable, but occasionally does have to
change as the corporate network grows and changes. This IP address used to be hard coded, but
after the fifth change to the IP address in two years, you have decided that this value should be
declared in the deployment descriptor so you do NOT have the recompile the web application
every time the IP address changes. Which deployment descriptor snippet accomplishes this goal?
A. <serlvet-param>
<name>WeatherServlet.hostIP</name>
<value>127.0.4.20</value>
</servlet-param>
B. <init-param>
<name>WeatherServlet.hostIP</name>
<value>127.0.4.20</value>
</init-param>
C. <servlet>
<!-- servlet definition here -->
<param-name>WeatherServlet.hostIP</param-name>
<param-value>127.0.4.20</param-value>
</servlet>
D. <init-param>
<param-name>WeatherServlet.hostIP</param-name>
<param-value>127.0.4.20</param-value>
</init-param>
E. <serlvet-param>
<param-name>WeatherServlet.hostIP</param-name>
<param-value>127.0.4.20</param-value>
</servlet-param>
Answer: D
QUESTION NO: 218
In which two locations can library dependencies be defined for a web application? (Choose two.)
A. the web application deployment descriptor
B. the /META-INF/dependencies.xml file
C. the /META-INF/MANIFEST.MF manifest file
D. the /META-INF/MANIFEST.MF manifest of a JAR in the web application classpath
Answer: C,D
QUESTION NO: 219
Which two about WAR files are true? (Choose two.)
A. WAR files must be located in the web application library directory.
B. WAR files must contain the web application deployment descriptor.
C. WAR files must be created by using archive tools designed specifically for that purpose.
D. The web container must serve the content of any META-INF directory located in a WAR file.
E. The web container must allow access to resources in JARs in the web application library
directory.
Answer: B,E
QUESTION NO: 220
Given this fragment from a Java EE deployment descriptor:
341. <error-page>
342. <exception-type>java.lang.Throwable</exception-type>
343. <location>/mainError.jsp</location>
344. </error-page>
345. <error-page>
346. <exception-type>java.lang.ClassCastException</exception-type>
347. <location>/castError.jsp</location>
348. </error-page>
If the web application associated with the fragment above throws a ClassCastException.
Which statement is true?
A. The deployment descriptor is invalid.
B. The container invokes mainError.jsp.
C. The container invokes castError.jsp.
D. Neither mainError.jsp nor castError.jsp is invoked.
Answer: C
Subscribe to:
Posts (Atom)