OCEJWCD Free Mock Exam

Question 1 of 20 [Introduction to Java Servlets]
Which is not true about CGI and Java Servlets?
Choice 1CGI programs are platform dependent while servlets are platform independent
Choice 2Both CGI and Servlets used for generating dynamic content for web applications
Choice 3Servlets are better scalability than CGI
Choice 4CGI runs on a container to get low-level services
Question 2 of 20 [Introduction to Java Servlets]
Which of the following cases are suitable for implementing Java Servlet?
Choice 1Obtain HTTP session information
Choice 2Generating performance chart as PNG
Choice 3Invoke business service
Choice 4Sets request information
Question 3 of 20 [Introduction to Java Server Pages]
Select the valid attributes of <jsp:getProperty>.
Choice 1name
Choice 2class
Choice 3property
Choice 4id
Choice 5scope
Question 4 of 20 [Implementing an MVC Design]
You are newly appointed as Lead Architect for ASP reengineering project. You need to replace ASP by appropriate Java EE technology.
What Java EE technology do you use?
Choice 1EJB
Choice 2JMS, Java and Servlets
Choice 3Java Applets
Choice 4JSP and Servlets
Choice 5JNDI, JAAS and JSP
Question 5 of 20 [Implementing an MVC Design]
One of the major benefits of using web application framework.
Choice 1It reduces development time for building common services
Choice 2It reduces development time for building business services
Choice 3It reduces development time for building JNDI services
Choice 4It reduces development time for building date access services
Question 6 of 20 [The servlet's environment]
Code :
12. public class MyServlet extends HttpServlet {
13. public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
14. PrintWriter out = response.getWriter();
15. HttpSession session = request.getSession();
16. out.write("Session status:1:"+session.isNew());
17. out.write(session.getId());
18. session.invalidate();
19. out.write("Session status:2:"+session.isNew());
20.}
21.}
What is the output displayed by the following servlet code?
Choice 1Session status:1:trueSession status:1:false
Choice 2Session status:1:trueSession status:1:true
Choice 3Session status:1:falseSession status:1:true
Choice 4Session status:1:falseSession status:1:false
Choice 5IllegalStateException will be thrown at line no.19
Question 7 of 20 [The servlet's environment]
Code :
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
@WebServlet(value="/MyServlet", name="MyServlet")
public class MyServlet extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { }
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { }
}

// enter.jsp
<html>
<body>
<form action="MyServlet" method="post">
<a href="/MyServlet">Submit form </a>
</form>
</body>
</html>
Which method will be called when a user clicks Submit form in enter.jsp?
Choice 1doPost
Choice 2doGet
Question 8 of 20 [Container facilities for servlets and JSPs]
EJB 3.1 addresses packaging complexity by removing the restriction that enterprise bean classes must be packaged in an ejb-jar file.
Which of the following statements are true about WAR file?
Choice 1EJB classes can be directly placed in the .war file, using the same packaging guidelines that apply to web application classes.
Choice 2We can place EJB classes under the WEB-INF/classes directory or in a .jar file within the WEB-INF/lib directory.
Choice 3We can place EJB classes under the WEB-INF/classes directory and NOT in a .jar file within the WEB-INF/lib directory.
Choice 4We can place EJB classes JAR files under the WEB-INF/lib directory and NOT in WEB-INF/classes directory.
Question 9 of 20 [Container facilities for servlets and JSPs]
You are working as a Java EE Web Developer in EPractize Labs product development activities. You need to add Servlet 3.0 Web fragments to register EPractize Labs Web Framework Controller Servlet (com.epractizelabs.framework.EPLController) and Servlet listener (com.epractizelabs.framework.EPLWebListener)
Select the valid web fragment
Choice 1<web-fragment>
<servlet>
<servlet-name> eplController </servlet-name>
<servlet-class> com.epractizelabs.framework.EPLController </servlet-class>
</servlet> <listener>
<listener-class> com.epractizelabs.framework.EPLWebListener </listener-class>
</listener>
</web-fragment>
Choice 2 <fragment>
<servlet>
<servlet-name> eplController </servlet-name>
<servlet-class> com.epractizelabs.framework.EPLController </servlet-class>
</servlet>
<listener>
<listener-class> com.epractizelabs.framework.EPLWebListener </listener-class>
</listener>
</fragment>
Choice 3 <WAR-fragment>
<servlet>
<servlet-name> eplController </servlet-name>
<servlet-class> com.epractizelabs.framework.EPLController </servlet-class>
</servlet>
<listener>
<listener-class> com.epractizelabs.framework.EPLWebListener </listener-class>
</listener>
</WAR-fragment>
Choice 4 <WEB-lib-fragment>
<servlet>
<servlet-name> eplController </servlet-name>
<servlet-class> com.epractizelabs.framework.EPLController </servlet-class>
</servlet> <listener>
<listener-class> com.epractizelabs.framework.EPLWebListener </listener-class>
</listener>
</WAR-lib-fragment>
Question 10 of 20 [Container facilities for servlets and JSPs]
Servlet 3.0 specification allows the application configuration resources to be composed of multiple configuration files (web.xml and web-fragment.xml),discovered and loaded from several different places in the application, the question of ordering must be addressed.
Which of the following can implement ordering?
Choice 1<absolute-ordering> element in the web.xml
Choice 2<absolute-ordering> element in the web-fragment.xml
Choice 3<ordering> element in web-fragment.xml
Choice 4<ordering> element in web.xml
Question 11 of 20 [More view facilities]
Which of the following is not an EL implicit object?
Choice 1initParam
Choice 2out
Choice 3paramValues
Choice 4param
Question 12 of 20 [More view facilities]
A developer wants to extract cookies in JSP page.
Which EL implicit object gives access to the cookies?
Choice 1cookie
Choice 2cookieName
Choice 3cookies
Choice 4cokie
Question 13 of 20 [Developing JSP pages]
Which of the following are true about page and pageContext in JSP pages?
Choice 1The page and pageContext are implicit JSP Objects.
Choice 2The pageContext is implicit JSP Object and page object must be explicitly created in init method.
Choice 3pageContext can forward request to another JSP page
Choice 4page can forward request to another JSP page
Question 14 of 20 [Developing JSP pages]
Code :
abstract class MyBean implements java.io.Serializable {
}
Which combination of jsp:useBean attributes used to access MyBean in your JSP?
Choice 1class and beanName
Choice 2id and scope
Choice 3class and type
Choice 4The class cannot be used as JSP bean
Question 15 of 20 [Developing JSP pages using custom tags]
You are building a web application that requires significant internationalization requirements. You have been tasked to create a custom tag that generates a message using the java.text.MessageFormat class.
The tag will take the messageKey attribute and a variable number of argument attributes with the format, arg <N>
Here is an example use of this tag and its output:
<tag:message messageKey='welcome' arg0='Brian' arg1='Christopher' />
Output : Welcome Brian Christopher !
Which Simple tag class definition accomplishes this goal of handling a variable number of tag attributes?
Choice 1 public class I18Tag extends SimpleTagSupport
implements VariableAttributes {
private Map attributes = new HashMap();
public void setVariableAttribute(String uri,
String name, Object value) {
this.attributes.put(name, value);
}

// more tag handler methods
}
Choice 2 public class I18Tag extends SimpleTagSupport
implements DynamicAttributes {
private Map attributes = new HashMap();
public void setDynamicAttribute(String uri, String name,
Object value) {
this.attributes.put(name, value);
}
// more tag handler methods
}
Choice 3 public class I18Tag extends SimpleTagSupport
implements DynamicAttributes {
private Map attributes = new HashMap();
public void putAttribute(String name, Object value) {
this.attributes.put(name, value);
}

// more tag handler methods
}
Choice 4 public class I18Tag extends SimpleTagSupport
implements VariableAttributes {
private Map attributes = new HashMap();
public void putAttribute(String name, Object value) {
this.attributes.put(name, value);
}

// more tag handler methods
}
Question 16 of 20 [Developing JSP pages using custom tags]
Code :
Consider the following mapping in the web.xml file.
<taglib>
<taglib-uri>/testTag</taglib-uri>
<taglib-location>/TLD/testTag.tld</taglib-location>
</taglib>
How would you correctly specify the above tag library in your JSP page?
Choice 1<%@ taglib uri="/testTag" id="t" %>
Choice 2<%@ taglib uri="/testTag" prefix="t" %>
Choice 3<%@ taglib name="/testTag" prefix="t" %>
Question 17 of 20 [More Controller facilities]
Which of the following statement is true about servlet filter?
Choice 1A filter must implement the destroy method.
Choice 2A filter must define initFilter method.
Choice 3A filter must implement the doFilter method.
Choice 4All of the above
Question 18 of 20 [More options for the Model]
Code :
@DataSourceDefinitions(
value = { @DataSourceDefinition(name = "java:app/env/MyDS1",
minPoolSize = 0,
initialPoolSize = 0,
className = "org.apache.derby.jdbc.ClientXADataSource",
portNumber = 1527,
serverName = "localhost",
user = "user",
password = "pass"
databaseName = "testdb",
properties = {"connectionAttributes=;create=true"}
),

@DataSourceDefinition(name = "java:comp/env/MyDS12",
minPoolSize = 0,
initialPoolSize = 0,
className = "org.apache.derby.jdbc.ClientXADataSource",
portNumber = 1527,
serverName = "localhost",
user = "user",
password = "pass",
databaseName = "testdb",
properties = {"connectionAttributes=;create=true"}
)
}
)

@Stateful
public class MyStatefulEJB {
...
...
}

Assume that MyStatefulEJB is packaged in WAR file.
Which of the following JNDI code snippet can obtain JDBC connection for MyDS1 in a servket?
Choice 1 try {
InitialContext ic = new InitialContext(); 
ds = (DataSource) ic.lookup("java:comp/env/MyDS11");
conn = ds.getConnection(); 
}
catch (SQLException se) {
throw new ServletException(se);
}
catch (NamingException ne) {
throw new ServletException(ne); }
Choice 2 try {
InitialContext ic = new InitialContext(); 
conn = (conn) ic.lookup("java:comp/env/MyDS11");
}
catch (SQLException se) {
throw new ServletException(se);
}
catch (NamingException ne) {
throw new ServletException(ne);
}
Choice 3 try {
InitialContext ic = new InitialContext();
ds = (DataSource) ic.lookup("JNDI:MyDS11");
conn = ds.getConnection(); 
}
catch (SQLException se) {
throw new ServletException(se);
}
catch (NamingException ne) {
throw new ServletException(ne);
}
Question 19 of 20 [Asynchronous web applications]
Dispatching from a servlet that has asyncSupported=true to one where asyncSupported is set to false is NOT allowed.
Choice 1True
Choice 2False
Question 20 of 20 [Web application security]
Which of the following code defines login-config for Form-based authentication?
Choice 1 <login-config>
<auth-method>FORM</auth-method>
<realm-name>file</realm-name>
<form-login-config>
<form-login-page>/logon.jsp</form-login-page>
<form-error-page>/logonError.jsp</form-error-page>
</form-login-config>
</login-config>
Choice 2 <login-config>
<auth-method>FORM</auth-method>
<realm-name>file</realm-name>
<form-config>
<login-page>/logon.jsp</form-login-page>
<error-page>/logonError.jsp</form-error-page>
</form-config>
</login-config>
Choice 3 <login-config>
<auth-method>FORM</auth-method>
<realm>file</realm>
<form-login-config>
<form-login-page>/logon.jsp</form-login-page>
<form-error-page>/logonError.jsp</form-error-page>
</form-login-config>
</login-config>
Choice 4 <login-config>
<authentication-method>FORM</authentication-method>
<realm-name>file</realm-name>
<form-login-config>
<form-login-page>/logon.jsp</form-login-page>
<form-error-page>/logonError.jsp</form-error-page>
</form-login-config>
</login-config>