JavaBeat

  • Home
  • Java
    • Java 7
    • Java 8
    • Java EE
    • Servlets
  • Spring Framework
    • Spring Tutorials
    • Spring 4 Tutorials
    • Spring Boot
  • JSF Tutorials
  • Most Popular
    • Binary Search Tree Traversal
    • Spring Batch Tutorial
    • AngularJS + Spring MVC
    • Spring Data JPA Tutorial
    • Packaging and Deploying Node.js
  • About Us
    • Join Us (JBC)
  • Privacy

OCMJEA 6 Syllabus

February 13, 2014 by Krishna Srinivasan Leave a Comment

Application Design Concepts and Principles

  • Identify the effects of an object-oriented approach to system design including the effect of encapsulation, inheritance, and use of interfaces.
  • Identify how the Separation of Concerns principle applies to the component model of a Java EE application; including client, the web and business component containers,  and the integration and resource layers.
  • Identify the correct interpretation of Separation of Concerns as it applies to the Java EE service layers, including component APIs, run-time containers, the operating system, and hardware resources.
  • Identify non-functional and quality-of-service requirements that influence application design, including trade-offs in performance, availability, and serviceability.

Common Architectures

  • Identify the appropriate strategy for deploying client applications to desktop and mobile platforms, the principles for designing a user interface and the benefits of applying client-tier patterns.
  • Identify best practices for exception handling, logging, and business tier patterns.
  • Identify design patterns that address specific challenges in the web tier, including authentication, authorization, and scaling and clustering to meet demand.
  • Identify Java EE technologies, including JMS, JCA and Web Services, and design patterns that address specific challenges in enterprise integration.
  • Identify the challenges in integrating enterprise resources, the Java EE technologies that address them (including JPA and JDBC), and the communication protocols that support tier-to-tier communication (including RMI, IIOP, and CORBA).

Integration and Messaging

  • Identify the APIs available for a Java EE technology-based system to communicating with external resources, including JPA, JDBC, RMI, Web Services, JMS, and JCA. Outline the benefits and drawbacks of each approach.
  • Describe the technologies used to integrate business components with Web Services, including XML over HTTP, JSON, SOAP and REST.
  • Identify and detail the technologies used to integrate business components with external resources, including JMS and JCA.
  • Identify how a Service Oriented Architecture (SOA) facilitates system integration and best practices.

Business Tier Technologies

  • Identify the correct EJB technology to apply for a given scenario, including entity classes, session beans, message-driven beans, timers, interceptors, and POJOs.
  • Identify benefits and drawbacks of different persistence technologies such as BMP, CMP, and JPA, including ease of development, performance, scalability, extensibility, and security.
  • Identify the benefits and drawbacks of implementing Web Services in the EJB component container.
  • Select the appropriate use of JPA and JPQL in a given scenario.

Web Tier Technologies

  • Identify the benefits and drawbacks of using URL rewriting and cookies to manage HTTP session state.
  • Identify appropriate uses for JSP and Servlet technology, and JavaServer Faces in a given Java EE application.
  • Identify the benefits of using an EJB container with a web container instead of a web container alone.
  • Identify the differences between client pull and server push architectures.
  • Identify the benefits and drawbacks of using a browser to access asynchronous, lightweight processes on the server.

Design Patterns

  • Demonstrate knowledge of Java EE design patterns including: Service Starter, Singleton, Bean Locator, Resource Binder, Dependency Inj ection, Payload Extractor, Context Holder, and Thread Tracker.
  • Select an appropriate pattern for a given application challenge from the following: Facade, Strategy, Observer, Composite, and Abstract Factory.
  • Identify a design pattern, using a description of its features, from the following:  Facade, Strategy, Observer, Composite, and Abstract Factory.
  • Identify the use of the law of leaky abstractions or a specific anti-pattern in a given scenario.

Security

  • Identify elements of the security model in the Java SE environment for remote clients, including Web Start, applets and the role of the SecurityManager class.
  • Select appropriate locations to implement Java EE security technologies or features in a UML component and deployment diagram.
  • Classify security threats to an enterprise application select measures an architect can propose to mitigate them.
  • Identify techniques associated with declarative and programmatic security, including the use of annotations, deployment descriptors, and JAAS technology.
  • Identify the security technologies  that apply to an application’s code, messaging and transport layers

Filed Under: Certifications Tagged With: OCMJEA, OCMJEA 6

OCPJP 7 Syllabus

February 13, 2014 by Krishna Srinivasan Leave a Comment

Java Class Design 

  • Use access modifiers: private, protected, and public
  • Override methods
  • Overload constructors and methods
  • Use the instanceof operator and casting
  • Use virtual method invocation
  • Override the hashCode, equals, and toString methods from the Object class to improve the functionality of your class.
  • Use package and import statements

Advanced Class Design 

  • Identify when and how to apply abstract classes
  • Construct abstract Java classes and subclasses
  • Use the static and final keywords
  • Create top-level and nested classes
  • Use enumerated types

Object-Oriented Design Principles 

  • Write code that declares, implements and/or extends interfaces
  • Choose between interface inheritance and class inheritance
  • Apply cohesion, low-coupling, IS-A, and HAS-A principles
  • Apply object composition principles (including has-a relationships)
  • Design a class using a Singleton design pattern
  • Write code to implement the Data Access Object (DAO) pattern
  • Design and create objects using a factory pattern

Generics and Collections

  • Create a generic class
  • Use the diamond for type inference
  • Analyze the interoperability of collections that use raw types and generic types
  • Use wrapper classes, autoboxing and unboxing
  • Create and use List, Set and Deque implementations
  • Create and use Map implementations
  • Use java.util.Comparator and java.lang.Comparable
  • Sort and search arrays and lists

String Processing 

  • Search, parse and build strings (including Scanner, StringTokenizer, StringBuilder, String and Formatter)
  • Search, parse, and replace strings by using regular expressions, using expression patterns for matching limited to: . (dot), * (star), + (plus), ?, \d, \D, \s, \S,  \w, \W, \b. \B, [], ().
  • Format strings using the formatting parameters: %b, %c, %d, %f, and %s in format strings.

Exceptions and Assertions 

  • Use throw and throws statements
  • Develop code that handles multiple Exception types in a single catch block
  • Develop code that uses try-with-resources statements (including using classes that implement the AutoCloseable interface)
  • Create custom exceptions
  • Test invariants by using assertions

Java I/O Fundamentals 

  • Read and write data from the console
  • Use streams to read from and write to files by using classes in the java.io package including BufferedReader, BufferedWriter, File, FileReader, FileWriter, DataInputStream, DataOutputStream, ObjectOutputStream, ObjectInputStream, and PrintWriter

Java File I/O (NIO.2) 

  • Operate on file and directory paths with the Path class
  • Check, delete, copy, or move a file or directory with the Files class
  • Read and change file and directory attributes, focusing on the BasicFileAttributes, DosFileAttributes, and PosixFileAttributes interfaces
  • Recursively access a directory tree using the DirectoryStream and FileVisitor interfaces
  • Find a file with the PathMatcher interface
  • Watch a directory for changes with the WatchService interface

Building Database Applications with JDBC 

  • Describe the interfaces that make up the core of the JDBC API (including the Driver, Connection, Statement, and ResultSet interfaces and their relationship to provider implementations)
  • Identify the components required to connect to a database using the DriverManager class (including the jdbc URL)
  • Submit queries and read results from the database (including creating statements, returning result sets, iterating through the results, and properly closing result sets, statements, and connections)
  • Use JDBC transactions (including disabling auto-commit mode, committing and rolling back transactions, and setting and rolling back to savepoints)
  • Construct and use RowSet objects using the RowSetProvider class and the RowSetFactory interface
  • Create and use PreparedStatement and CallableStatement objects

Threads 

  • Create and use the Thread class and the Runnable interface
  • Manage and control thread lifecycle
  • Synchronize thread access to shared data
  • Identify code that may not execute correctly in a multi-threaded environment.

Concurrency 

  • Use collections from the java.util.concurrent package with a focus on the advantages over and differences from the traditional java.util collections.
  • Use Lock, ReadWriteLock, and ReentrantLock classes in the java.util.concurrent.locks package to support lock-free thread-safe programming on single variables.
  • Use Executor, ExecutorService, Executors, Callable, and Future to execute tasks using thread pools.
  • Use the parallel Fork/Join Framework

Localization 

  • Read and set the locale by using the Locale object
  • Build a resource bundle for each locale
  • Call a resource bundle from an application
  • Format dates, numbers, and currency values for localization with the NumberFormat and DateFormat classes (including number format patterns)
  • Describe the advantages of localizing an application
  • Define a locale using language and country codes

Filed Under: Certifications Tagged With: OCPJP, OCPJP 7

OCPJBCD / SCBCD 5 Exam

February 13, 2014 by Krishna Srinivasan Leave a Comment

OCPJBCD / SCBCD 5 Mock Exams:

  • Mock Exam 1
  • Mock Exam 2
  • Mock Exam 3
  • Mock Exam 4

The Syllabus for the OCPJBCD / SCBCD 5 exam is :

Section 1: EJB 3.0 Overview

  1. Identify the uses, benefits, and characteristics of Enterprise JavaBeans technology, for version 3.0 of the EJB specification.
  2. Identify the APIs that all EJB 3.0 containers must make available to developers.
  3. Identify correct and incorrect statements or examples about EJB programming restrictions.
  4. Match the seven EJB roles with the corresponding description of the role’s responsibilities.
  5. Describe the packaging and deployment requirements for enterprise beans.
  6. Describe the purposes and uses of annotations and deployment descriptors, including how the two mechanisms interact, how overriding is handled, and how these mechanisms function at the class, method, and field levels.

Section 2: General EJB 3.0 Enterprise Bean Knowledge

  1. Identify correct and incorrect statements or examples about the lifecycle of all 3.0 Enterprise Bean instances, including the use of the @PostConstruct and @PreDestroy callback methods.
  2. Identify correct and incorrect statements or examples about interceptors, including implementing an interceptor class, the lifecycle of interceptor instances, @AroundInvoke methods, invocation order, exception handling, lifecycle callback methods, default and method level interceptors, and specifying interceptors in the deployment descriptor.
  3. Identify correct and incorrect statements or examples about how enterprise beans declare dependencies on external resources using JNDI or dependency injection, including the general rules for using JNDI, annotations and/or deployment descriptors, EJB references, connection factories, resource environment entries, and persistence context and persistence unit references.
  4. Identify correct and incorrect statements or examples about Timer Services, including the bean provider’s view and responsibilities, the TimerService, Timer and TimerHandle interfaces, and @Timeout callback methods.
  5. Identify correct and incorrect statements or examples about the EJB context objects that the container provides to 3.0 Session beans and 3.0 Message-Driven beans, including the security, transaction, timer, and lookup services the context can provide.
  6. Identify correct and incorrect statements or examples about EJB 3.0 / EJB 2.x interoperability, including how to adapt an EJB 3.0 bean for use with clients written to the EJB 2.x API and how to access beans written to the EJB 2.x API from beans written to the EJB 3.0 API.

Section 3: EJB 3.0 Session Bean Component Contract & Lifecycle

  1. Identify correct and incorrect statements or examples that compare the purpose and use of Stateful and Stateless Session Beans.
  2. Identify correct and incorrect statements or examples about remote and local business interfaces for Session Beans.
  3. Write code for the bean classes of Stateful and Stateless Session Beans.
  4. Identify correct and incorrect statements or examples about the lifecycle of a Stateful Session Bean including the @PrePassivate and @PostActivate lifecycle callback methods and @Remove methods.
  5. Given a list of methods of a Stateful or Stateless Session Bean class, define which of the following operations can be performed from each of those methods: SessionContext interface methods, UserTransaction methods, access to the java:comp/env environment naming context, resource manager access, and other enterprise bean access.
  6. Identify correct and incorrect statements or examples about implementing a session bean as a web service endpoint, including rules for writing a web service endpoint interface and use of the @WebService and @WebMethod annotations.
  7. Identify correct and incorrect statements or examples about the client view of a session bean, including the client view of a session object’s life cycle, obtaining and using a session object, and session object identity.

Section 4: EJB 3.0 Message-Driven Bean Component Contract

  1. Develop code that implements a Message-Driven Bean Class.
  2. Identify correct and incorrect statements or examples about the interface(s) and methods a JMS Message-Driven bean must implement, and the required metadata.
  3. Describe the use and behavior of a JMS message driven bean, including concurrency of message processing, message redelivery, and message acknowledgement.
  4. Identify correct and incorrect statements or examples about the client view of a message driven bean.

Section 5: Java Persistence API Entities

  1. Identify correct and incorrect statements or examples about the characteristics of Java Persistence entities.
  2. Develop code to create valid entity classes, including the use of fields and properties, admissible types, and embeddable classes.
  3. Identify correct and incorrect statements or examples about primary keys and entity identity, including the use of compound primary keys.
  4. Implement association relationships using persistence entities, including the following associations: bidirectional for @OneToOne, @ManyToOne, @OneToMany, and @ManyToMany; unidirectional for @OneToOne, @ManyToOne, @OneToMany, and @ManyToMany.
  5. Given a set of requirements and entity classes choose and implement an appropriate object-relational mapping for association relationships.
  6. Given a set of requirements and entity classes, choose and implement an appropriate inheritance hierarchy strategy and/or an appropriate mapping strategy.
  7. Describe the use of annotations and XML mapping files, individually and in combination, for object-relational mapping.

Section 6: Java Persistence Entity Operations

  1. Describe how to manage entities, including using the EntityManager API and the cascade option.
  2. Identify correct and incorrect statements or examples about entity instance lifecycle, including the new, managed, detached, and removed states.
  3. Identify correct and incorrect statements or examples about EntityManager operations for managing an instance’s state, including eager/lazy fetching, handling detached entities, and merging detached entities.
  4. Identify correct and incorrect statements or examples about Entity Listeners and Callback Methods, including: @PrePersist, @PostPersist, @PreRemove, @PostRemove, @PreUpdate, @PostUpdate, and @PostLoad, and when they are invoked.
  5. Identify correct and incorrect statements about concurrency, including how it is managed through the use of @Version attributes and optimistic locking.

Section 7: Persistence Units and Persistence Contexts

  1. Identify correct and incorrect statements or examples about JTA and resource-local entity managers.
  2. Identify correct and incorrect statements or examples about container-managed persistence contexts.
  3. Identify correct and incorrect statements or examples about application-managed persistence contexts.
  4. Identify correct and incorrect statements or examples about transaction management for persistence contexts, including persistence context propagation, the use of the EntityManager.joinTransaction() method, and the EntityTransaction API.
  5. Identify correct and incorrect statements or examples about persistence units, how persistence units are packaged, and the use of the persistence.xml file.
  6. Identify correct and incorrect statements or examples about the effect of persistence exceptions on transactions and persistence contexts.

Section 8: Java Persistence Query Language

  1. Develop queries that use the SELECT clause to determine query results, including the use of entity types, use of aggregates, and returning multiple values.
  2. Develop queries that use Java Persistence Query Language syntax for defining the domain of a query using JOIN clauses, IN, and prefetching.
  3. Use the WHERE clause to restrict query results using conditional expressions, including the use of literals, path expressions, named and positional parameters, logical operators, the following expressions (and their NOT options): BETWEEN, IN, LIKE, NULL, EMPTY, MEMBER [OF], EXISTS, ALL, ANY, SOME, and functional expressions.
  4. Develop Java Persistence Query Language statements that update a set of entities using UPDATE/SET and DELETE FROM.
  5. Declare and use named queries, dynamic queries, and SQL (native) queries.
  6. Obtain javax.persistence.Query objects and use the javax.persistence.Query API.

Section 9: Transactions

  1. Identify correct and incorrect statements or examples about bean-managed transaction demarcation.
  2. Identify correct and incorrect statements or examples about container-managed transaction demarcation, and given a list of transaction behaviors, match them with the appropriate transaction attribute.
  3. Identify correct and incorrect statements or examples about transaction propagation semantics.
  4. Identify correct and incorrect statements or examples about specifying transaction information via annotations and/or deployment descriptors.
  5. Identify correct and incorrect statements or examples about the use of the EJB API for transaction management, including getRollbackOnly, setRollbackOnly and the SessionSynchronization interfaces.

Section 10: Exceptions

  1. Identify correct and incorrect statements or examples about exception handling in EJB.
  2. Identify correct and incorrect statements or examples about application exceptions and system exceptions in session beans and message-driven beans, and defining a runtime exception as an application exception.
  3. Given a list of responsibilities related to exceptions, identify those which are the bean provider’s, and those which are the responsibility of the container provider. Be prepared to recognize responsibilities for which neither the bean nor container provider is responsible.
  4. Identify correct and incorrect statements or examples about the client’s view of exceptions received from an enterprise bean invocation.
  5. Given a particular method condition, identify the following: whether an exception will be thrown, the type of exception thrown, the container’s action, and the client’s view.

Section 11: Security Management

  1. Match security behaviors to declarative security specifications (default behavior, security roles, security role references, and method permissions).
  2. From a list of responsibilities, identify which roles are responsible for which aspects of security: application assembler, bean provider, deployer, container provider, system administrator, or server provider.
  3. Identify correct and incorrect statements or examples about use of the isCallerInRole and getCallerPrincipal EJB programmatic security APIs.
  4. Given a security-related deployment descriptor tag or annotation, identify correct and incorrect statements and/or code related to that tag

Filed Under: Certifications Tagged With: OCPJBCD

OCEJWCD 6 Exam

February 8, 2014 by Krishna Srinivasan Leave a Comment

The OCEJWCD  certification provides knowledge required to develop Java EE 6 Enterprise applications using JSP and Servlets. This exam covers major improvements in Java EE 6 like web fragments, asynchronous servlet, annotations to create servlet or filter, etc. The following are the list of topics covered as part of this certification exam.

  1. Introduction to Java Servlets
  2. Introduction to Java Server Pages
  3. Implementing an MVC Design
  4. The servlet’s environment
  5. Container facilities for servlets and JSPs
  6. More view facilities
  7. Developing JSP pages
  8. Developing JSP pages using custom tags
  9. More Controller facilities
  10. More options for the Model
  11. Asynchronous web applications
  12. Web application security

OCEJWCD Mock Exams

  • Mock Exam – 1
  • Mock Exam – 2
  • Mock Exam – 3
  • Mock Exam – 4
  • Mock Exam – 5
  • Mock Exam – 6
  • Mock Exam – 7

Filed Under: Certifications Tagged With: OCEJWCD, OCEJWCD 6

OCEJWCD 6 Mock Exam – 7

February 7, 2014 by Krishna Srinivasan Leave a Comment

1 . Consider the following code:

[code lang=”java”]
public void doGet(HttpServletRequest req, HttpServlerResponse res)
{
PrintWriter out = res.getWriter();
out.println("Unable to find resource.");
//1
response.sendError(404);
}
[/code]

Which of the following lines, when inserted at //1, will ensure that an IllegalStateException is NOT thrown?

Choose the one below:

  1. res.clear();
  2. res.empty();
  3. res.remove();
  4. if(!res.isCommitted())
  5. if( res.getStatus() != res.COMMITTED)

2 . Which of the following statements are correct JSP directives?

  1. <%@ page %>
  2. <%! taglib uri=”http://www.abc.com/tags/util” prefix=”util” %>
  3. <% include file=”/copyright.html”%>
  4. <%@ taglib uri=”http://www.abc.com/tags/util” prefix=”util” %>
  5. <%$ page language=”java” import=”com.abc.*”%>

3 . Consider the following contents for two JSP files:

[code]
In file companyhome.jsp:

&lt;html&gt;&lt;body&gt;

Welcome to ABC Corp!

&lt;jsp:include page=&quot;companynews.jsp&quot; /&gt;

&lt;/body&gt;&lt;/html&gt;

&lt;%@ page errorPage=&quot;simpleerrorhandler.jsp&quot; %&gt;
[/code]

 

[code]
In file companynews.jsp:

&lt;%@ page errorPage=&quot;advancederrorhandler.jsp&quot; %&gt;

&lt;h3&gt;Todays News&lt;/h3&gt;
[/code]

Choose the one below:

  1. When companyhome.jsp is requested, the output will contain “welcome…” as well as “Todays News”
  2. companyhome.jsp will not compile
  3. companynews.jsp will not compile
  4. Both the files will compile but will throw an exception at runtime
  5. None of these

4 . Which HTTP method is used in FORM based Authentication?

  1. POST
  2. GET
  3. FORM
  4. HEAD

5 . Consider the following code snippets. What will be displayed on the browser when a GET request is sent to FirstServlet assuming that the buffer is large enough to hold all the data before sending the data to the client?

[code]
In the doGet() of FirstServlet:

PrintWriter out = response.getWriter();

out.println(&quot;&lt;html&gt;&lt;body&gt;Page 1&quot;);

RequestDispatcher rd = response.getRequestDispatcher(&quot;SecondServlet&quot;);

rd.forward(request, response);
[/code]

 

[code]
In the doGet() of SecondServlet:

PrintWriter out = response.getWriter();

out.println(&quot;&lt;br&gt;Page 2&lt;/body&gt;&lt;/html&gt;&quot;);
[/code]

Choose the one below:

  1. Only Page1
  2. Only Page2
  3. Page1 and Page2
  4. IllegalStateException at Runtime

6 . Which of the given options are equivalent?

  1. <% Hashtable ht = new Hashtable(); %>
  2. <%= Hashtable ht = new Hashtable() %>
  3. <jsp:scriptlet>Hashtable ht = new Hashtable();</jsp:scriptlet>
  4. <jsp:code>Hashtable ht = new Hashtable();</jsp:code>
  5. <jsp:scriptlet>Hashtable ht = new Hashtable()</jsp:scriptlet>

7 . When a session becomes invalid, which method is invoked on a session attribute implementing an appropriate interface?

  1. sessionInvalidated() of HttpSessionListener
  2. sessionDestroyed() of HttpSessionListener
  3. valueUnbound() of HttpSessionAttributeListener
  4. valueUnbound() of HttpSessionBindingListener
  5. valueUnbound() of HttpSessionListener

8 . Your jsp page connects to the database and retrieves the data.It also formats the data and displays it to the client.Any of these operations can throw exceptions but you do not want to catch them all in this page and so you have written another jsp page that is meant to handle any kind of exceptions.
How would you associate that error page named “error.jsp” with this page?

  1. Add <%@errorPage=”error.jsp”%> in this page
  2. Add <%@page errorPage=”error.jsp”%> in this page
  3. Add <%@page isErrorPage=”true”%> in error.jsp
  4. Add <%@isErrorPage=”true”%> in error.jsp

9 . Consider the HTML code shown in the exhibit. Which of the following method calls can retrieve the “email” value sent from the browser?

[code lang=”html”]
&lt;html&gt;&lt;body&gt;

&lt;form action=&quot;/myapp/servlet/EmailCatcherServlet&quot;&gt;

Please enter your email: &lt;input type=&quot;text&quot; name=&quot;email&quot;&gt;

&lt;input type=&quot;submit&quot;&gt;

&lt;/form&gt;

&lt;/body&gt;&lt;/html&gt;
[/code]

Choose the one below:

  1. getParameter(“email”) of ServletRequest
  2. getParameterValues(“email”) of ServletRequest
  3. getField(“email”) of HttpServletRequest
  4. getFormValue(“email”) of HttpServletRequest
  5. getParameters(“email”) of HttpServlet

10 . What will be the output?

[code lang=”java”]
&lt;% { %&gt;

&lt;jsp:useBean id=&quot;sb&quot; class=&quot;java.lang.StringBuffer&quot; /&gt;

sb.append(&quot;Hello&quot;);

&lt;% } %&gt;

&lt;%=sb%&gt;
[/code]

Choose the one below:

  1. It will print null
  2. It will print “Hello”
  3. It will not compile because <jsp:useBean> cannot be used inside a block
  4. It will not compile because StringBuffer is not a bean
  5. None of these

11 . Which HTTP method would you use to test the validity, accesibility, or modification time of a hyperlink?

  1. GET
  2. POST
  3. HEAD
  4. OPTIONS
  5. PUT

12 . A function has been defined in a tag library descriptor as follows:

[code]
&lt;taglib&gt;

…

&lt;function&gt;

&lt;name&gt;transform&lt;/name&gt;

&lt;function-class&gt;com.enthu.Functions&lt;/function-class&gt;

&lt;function-signature&gt;java.lang.String transformString(String)&lt;/function-signature&gt;

&lt;/function&gt;

…

&lt;/taglib&gt;
[/code]

Which of the following statements are correct?

Choose the one below:

  1. The Function class must have a method with the signature: public String transform(String arg);
  2. The Function class must have a function with the signature: public String transformString(String arg);
  3. The Function class may have any method of the type: public static XXX(String s); but the method name (ie. XXX) must be mapped to “transform” in web.xml
  4. The Function class may have any method of the type: public static XXX(String s); but the method name (ie. XXX) must be mapped to “transformString” in web.xml
  5. None of these

13 . In your report.jsp page, you want to include the output of “customer.jsp” page. But this page requires an additional parameter “custid”, which is not present in the request?
Which of the following code snippents does this?

[code]
1. &lt;jsp:include page=&quot;customer.jsp&quot; custid=&quot;1234&quot;/&gt;

2. &lt;jsp:include page=&quot;customer.jsp&quot;&gt;

&lt;jsp:param&gt;

&lt;name&gt;custid&lt;/name&gt;

&lt;value&gt;1234&lt;/value&gt;

&lt;/jsp:param&gt;

&lt;/jsp:include&gt;

3. &lt;jsp:include page=&quot;customer.jsp&quot; param-name=&quot;custid&quot; param-value=&quot;1234&quot;/&gt;

4. &lt;jsp:include page=&quot;customer.jsp&quot;&gt;

&lt;jsp:param name=&quot;custid&quot; value=&quot;1234&quot;/&gt;

&lt;/jsp:include&gt;
[/code]

Choose the one below:

  1. 1
  2. 2
  3. 3
  4. 4

14 . Which of the following statements are correct regarding the import tag of JSTL?

  1. The String value of the imported content can be made available for use outside of the tag in ‘var’ variable
  2. If the url contains a relative path, then the resource must exist in the same webapp
  3. import tag is more efficient than jsp:include action in the case when large amount of data is imported only to be given to another tag
  4. import tag is useful to convert URL when cookies are not supported by the client
  5. The content imported by the import tag can be made available only through a String object

15 . What are the implications of using the HTTP GET method for a form submission?

  1. You cannot pass binary data to the server
  2. You cannot send unlimited (or a lot of) data to the server
  3. You cannot send multiple values for one parameter to the server
  4. You can only reply with the HEADER information in the response
  5. The parameters will be appended to the URL as a query string

16 . It important to note that response of a POST request are never cached?

[code]
1. &lt;taglib&gt;

&lt;taglib-uri&gt;/binomial&lt;/taglib-uri&gt;

&lt;taglib-location&gt;/WEB-INF/MathLib.tld&lt;/taglib-location&gt;

&lt;/taglib&gt;

2. &lt;taglib&gt;

&lt;taglib-uri&gt;/binomial&lt;/taglib-uri&gt;

&lt;taglib-location&gt;/WEB-INF/MathLib.jar&lt;/taglib-location&gt;

&lt;/taglib&gt;

3. &lt;taglib id=&quot;ABC_MATH_LIB&quot;&gt;

&lt;taglib-uri&gt;/binomial&lt;/taglib-uri&gt;

&lt;taglib-location&gt;/WEB-INF/MathLib.tld&lt;/taglib-location&gt;

&lt;/taglib&gt;

4. &lt;taglib name=&quot;ABC_MATH_LIB&quot;&gt;

&lt;taglib-uri&gt;/binomial&lt;/taglib-uri&gt;

&lt;taglib-location&gt;/WEB-INF/MathLib.jar&lt;/taglib-location&gt;

&lt;/taglib&gt;

5. &lt;taglib author=&quot;ABCINC&quot;&gt;

&lt;taglib-uri&gt;/binomial&lt;/taglib-uri&gt;

&lt;taglib-location&gt;/WEB-INF/MathLib.tld&lt;/taglib-location&gt;

&lt;/taglib&gt;
[/code]

Choose the one below:

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5

17 . Consider the following jsp code:

[code lang=”html”]
&lt;html&gt;

&lt;head&gt;

&lt;% int k = 0; %&gt;

&lt;/head&gt;

&lt;body&gt;

&lt;/body&gt;

&lt;/html&gt;
[/code]

In which method of the generated servlet will the declaration for ‘k’ be placed?

Choose the one below:

  1. This will not compile as you cannot put jsp code in the <head> element
  2. init()
  3. doGet()
  4. _jspService()
  5. constructor of the servlet

18 . Which event is received by a registered listener when an attribute is added to HttpSession?

  1. HttpSessionChangeEvent
  2. HttpSessionEvent
  3. HttpAttributeChangeEvent
  4. HttpSessionBindingEvent
  5. HttpAttributeEvent

19 . You are using a tag library with prefix “generator”, which supports a tag named “random”.This tag generates a random number and sets it to a variable named “value”?
Which of the following will output this value in the page?

Choose the one below:

  1. <generator:random>value</generator:random>
  2. <generator:random><%=value%></generator:random>
  3. <generator:random><% int value;%> <%=value%></generator:random>
  4. <generator:random><%getParameter(“value”)%></generator:random>
  5. None of the above

20 . Identify the techniques that can be used to implement ‘sessions’ if the client browser does not support cookies?

  1. Using Http headers
  2. Using https protocol
  3. Hidden form fields
  4. URL rewriting
  5. It cannot be done without cookie support

21 . Which of the following are valid JSP scriptlets?

  1. <% String uid = LoginHelper.login(request) %>
  2. <% String uid = LoginHelper.login(request); %>
  3. <%! String uid = LoginHelper.login(request) %>
  4. <%@ String uid = LoginHelper.login(request) %>
  5. <% for(int i=0; i< 10; i++) { out.println(i); } %>

22 . Consider the following web.xml code snippet:

[code lang=”xml”]

&lt;servlet&gt;

&lt;servlet-name&gt;BankServlet&lt;/servlet-name&gt;

&lt;servlet-class&gt;com.abc.bankapp.BankServlet&lt;/servlet-class&gt;

&lt;security-role-ref&gt;

&lt;role-name&gt;manager&lt;/role-name&gt;

&lt;role-link&gt;supervisor&lt;/role-link&gt;

&lt;/security-role-ref&gt;

&lt;/servlet&gt;
[/code]

Which of the following statements are correct?

Choose the one below:

  1. The servlet code should use “manager” as a parameter in request.isUserInRole() method
  2. The servlet code can use “manager” or “supervisor” as a parameter in request.isUserInRole() method
  3. The servlet code should use”supervisor” as a parameter in request.isUserInRole() method
  4. The role of “manager” must be defined in the servlet container
  5. None of these

23 . You are designing a complex webapp that uses multi tier architecture. The application must provide interfaces for HTML as well as XML and should be maintainable?
Which design pattern would you use?

Choose the one below:

  1. Data Access Object
  2. Business Deligate
  3. MVC
  4. Remote Method Invocation
  5. Transfer Object

24 . Which of the following directives are applicable ONLY for tag files?

  1. attribute
  2. variable
  3. page
  4. include
  5. import
  6. tag

25 . Which of the following are correct about FORM based authentication mechanism?

  1. HTML FORM is used to capture the username and password of the user
  2. Password is transmitted as plain text
  3. Password is transmitted in an encrypted form
  4. Password is transmitted either in encrypted text or in plain text depending on the browser
  5. This mechanism can be used over HTTPS

26 . Which pattern allows you to replace the presentation logic without much impact on the data representation?

  1. Model View Controller
  2. Business Delegate
  3. Transfer Object
  4. Data Access Object
  5. Bimodal DataAccess

27 . Identify the elements that help describe the attribute characteristics of a JSP custom tag in a TLD file?

  1. value
  2. name
  3. description
  4. rtexprvalue
  5. class

28 . Select the correct return types for ServletContext.getResource() and ServletContext.getResourceAsStream() methods?

  1. java.io.Resource and java.io.InputStream
  2. java.io.Resource and java.io.BufferedInputStream
  3. java.net.URL and java.io.InputStream
  4. java.io.File and java.io.InputStream
  5. java.net.URL and java.io.FileInputStream

29 . Which of the following are valid values for the <transport-guarantee> element?

  1. CONFIDENTIAL
  2. INTEGRAL
  3. SECURE
  4. ENCRYPTED
  5. NONE

30 . Which method of ServletResponse would you use to set its content type?

  1. setParameter
  2. setHeader
  3. setAttribute
  4. setContentType
  5. None of the above

31 . Which of the following lines can be used to retrieve a servlet initialization parameter “dbname” from the init() method of a servlet?

[code lang=”java”]
public void init()

{

String dbname = //1 : Insert line here

}
[/code]

Choose the one below:

  1. getServletConfig().getParameter(“dbname”);
  2. getServletConfig().getInitParameter(“dbname”);
  3. getServletContext().getInitParameter(“dbname”);
  4. getInitParameter(“dbname”); E.getInitParameterValue(“dbname”);

Answers

1 : 4 is correct.

2 : 1 & 4 is correct.

3 : 1 is correct.

4 : 1 is correct.

5 : 2 is correct.

6 : 1 & 3 is correct.

7 : 4 is correct.

8 : 2 & 3 is correct.

9 : 1 & 2 is correct.

10 : 5 is correct.

11 : 3 is correct.

12 : 5 is correct.
Explanation: The Function class must have a method with signature: public static String transformString(String arg);
1 is incorrect. The method name must be the same as given in <function-signature> element.
2 is incorrect. Method name is correct but it should also be static.

13 : 4 is correct.

14 : 1 & 3 is correct.

15 : 1,2 & 5 is correct.

16 : 1,2 & 3 is correct.

17 : 4 is correct.
Explanation: This is a scriptlet and they always go inside the service method. ie. they are local to the request. 1 is incorrect. You can put JSP code anywhere

18 : 4 is correct.
Explanation:Following is the mapping of Listeners and their corresponding events.
HttpSessionListener : HttpSessionEvent
HttpSessionAttributeListener : HttpSessionBindingEvent
HttpSessionBindingListener : HttpSessionBindingEvent
Observe that both – HttpSessionAttributeListener and HttpSessionBindingListener, use HttpSessionBindingEvent.

19 : 2 is correct.
Explanation: 3 is incorrect It’ll give an exception saying value is not initialized!

20 : 2,3 & 4 is correct.
Explanation: 2 is correct Unlike HTTP, HTTPS uses SSL which is a stateful protocol.
3 is correct Remember that this is a non-standard and obsolete way.
This can only be done in an application specific way and requires that the page has a form.

21 : 2 & 5 is correct.
Explanation: 1 is incorrect. It does not have an ending semicolon
3 is incorrect. ! is used for declarations
4 is incorrect. @ is used for directives

22 : 1 is correct.
Explanation:4 is incorrect “supervisor” must be defined in the container. For example, in conf/tomcat-users.xml for Tomcat.
<security-role-ref> is used to map the role names hard coded in the servlet code to the actual role names defined in the servlet container.

23 : 3 is correct.
Explanation: The statement “…should provide XML and HTML interfaces…” means the same data is represented in different ways, therefore this is MVC.

24 : 1,2 & 6 is correct.
Explanation: 2 Valid only for tag files.
4 is incorret include directive is valid for regular JSP file also
5 is incorrect No such directive

25 : 1,2 & 5 is correct.
Explanation: 3 is incorrect This is done in HTTP Digest authentication mechanism

26 : 1 is correct.
Explanation: 1 is correct. A view (ie. the presentation of data) knows how to present the data and so can be replaced with another view without any impact on the data representation.
2 is incorrect. This allows plug and play between back end logic and the front end.
4 is incorrect. This allows plug and play between the data container (the DB) and data requestor.

27 : 2,3 & 4 is correct.
Explanation: An attribute element describes the attribute for a tag. Following is its definition.
<!ELEMENT attribute (name, required? , rtexprvalue?, type?, description?) >

28 : 3 is correct.

29 : 1,2 & 5 is correct.

30 : 4 is correct.

31 : 2 & 4 is correct.
Explanation: Calling getServletConfig() from the init() method returns the ServletConfig object for this servlet and calling getInitParameter(…) on the ServletConfig object returns the value of that parameter.

Filed Under: Certifications Tagged With: OCEJWCD, OCEJWCD 6

OCEJWCD 6 Mock Exam – 6

February 7, 2014 by Krishna Srinivasan Leave a Comment

1 . Which constant is used to notify the container to reevaluate the custom tag’s body?

  1. EVAL_BODY
  2. EVAL_BODY_TAG
  3. EVAL_BODY_AGAIN
  4. EVAL_BODY_INCLUDE

2 . Which of the following statements regarding the JSP action tag are TRUE?

  1. Provides translation-time instructions to the JSP engine
  2. Can be used to declare a JavaBean instance in a JSP page
  3. Can be used to generate HTML code to embed an applet on a web page
  4. User-defined actions can be created
  5. Language is a standard JSP action

3 . Which of the following methods can be used to pass request to another servlet to handle by using the RequestDispatcher?

  1. request(ServletRequest req, ServletResponse res)
  2. include(ServletRequest req, ServletResponse res)
  3. dispatch(ServletRequest req, ServletResponse res)
  4. forward(ServletRequest req, ServletResponse res)
  5. process(ServletRequest req, ServletResponse res)

4 . What will be the output?

[code lang=”java”]
import javax.servlet.*;
import javax.servlet.http.*;

public class MyServlet extends GenericServlet {

public void init() { //1
// Do something
}

public void init(ServletConfig config) //2
throws ServletException{
// Do something
super.init(config); //3
}

public void destroy() { //4
// Do something
}

public void service(ServletRequest req, //5
ServletResponse res) {
// Do something
}
}
[/code]

Choose the one below:

  1. Method //1 is necessary for this code to compile
  2. Method //2 is necessary for this code to compile
  3. Line //3 is necessary for this code to run
  4. Method //4 is necessary for this code to compile
  5. Method //5 is necessary for this code to compile

5 . Which pattern is normally used to encapsulate database SQL statement?

  1. Value Object
  2. Data Value Object
  3. Data Access Object
  4. Business Object
  5. Business Delegate

6 . For special character used in request URI, which of the following statements are correct?

  1. The ampersand (&) is used to separate name/value pairs
  2. The plus sign (+) is used to fill blank space
  3. The dash sign (-) is used to separate the name and value
  4. The percent sign (%) is used to start a query string

7 . Which statements are TRUE regarding the HttpServlet method doPost(HttpServletRequest req, HttpServletResponse res)?

  1. The method is called by the server (via the service method) to allow a servlet to handle a POST or PUT request
  2. The method is called by the server (via the service method) to allow a servlet to handle a POST or GET request
  3. The method is called by the server (via the service method) to allow a servlet to handle a POST request
  4. The method is called by the server (via the service method) to allow a servlet to handle a GET request
  5. The method allows the client to send data of unlimited length to the Web server a single time
  6. Operations requested through this method will NEVER have side effects

8 . Which of the following design pattern is used to reduce the amount of network traffic when transferring data?

  1. Model View Controller
  2. Data Access Object
  3. Business Delegate
  4. Value Object

9 . What is the authentication type which uses digital certificates as a security mechanism for a web based application?

10 . Which of the following method is used to retrieve the value associated to the init parameter defined in the init-param tag?

  1. getParameter(String name)
  2. getInitParameter(String name)
  3. getParameters()
  4. getInitParameterValue(String name)

11 . Which of the following statements are TRUE for the code given below?

[code]
int MAX_AGE;
Cookie cookie = new Cookie("user", user);
cookie.setMaxAge(MAX_AGE);
response.addCookie(cookie);
[/code]

Choose the one below:

  1. If MAX_AGE = 10; the cookie will expire after 10 seconds
  2. If MAX_AGE = 10; the cookie will expire after 600 seconds
  3. If MAX_AGE = 0; the cookie will be deleted
  4. If MAX_AGE = -1; the cookie is not stored persistently
  5. If MAX_AGE = -1; the code will generate run-time error

12 . In which directory you will most likely find the file myBaseUtil.jar?

  1. example/WEB-INF
  2. example/lib
  3. example/WEB-INF/lib
  4. example/WEB-INF/classes
  5. example/META-INF/lib

13 . Which of the following requirements are needed for FORM based authentication in a web based application?

  1. The session attribuite j_sessionid must be set
  2. The action or url must be j_security_check
  3. The name attribute for the username must be j_username
  4. The form method must be POST
  5. The name attribute for the password must be j_password
  6. Client side cookie must be enabled

14 . Which of the following deployment descriptor snippet will map the following request URI:

[code]
/tech/hello/index.jsp
[/code]

for web application with context path as “tech”?

[code]
1. <servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/hello/*</url-pattern>
</servlet-mapping>

2. <servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/hello/*.jsp</url-pattern>
</servlet-mapping>

3. <servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/hello/index.jsp</url-pattern>
</servlet-mapping>

4. <servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>hello/*</url-pattern>
</servlet-mapping>
[/code]

Choose the one below:

  1. 1
  2. 2
  3. 3
  4. 4

15 . Which of the following methods will enable you to get one or more values from a request object?

  1. getParameter(String name)
  2. getParameters(String name)
  3. getAllParameters()
  4. getParameterValues(String name)
  5. getAllAttributes()

16 . Is the following statement TRUE or FALSE?

[code]
The four methods for session management in the context of web-based application are: Cookie, HttpSession object, URL rewriting and Hidden value.
[/code]

Choose the one below:

  1. True
  2. False

17 . Which of the following packages are implicitly imported in the JSP page?

  1. java.lang.*
  2. java.util.*
  3. javax.servlet.*
  4. javax.servlet.jsp.*
  5. javax.servlet.jsp.tagext.*

18 . Which of the following is NOT an authentication method used by a web container?

  1. BASIC
  2. DIGEST
  3. SSL
  4. FORM

19 . Which methods can be used for writing logging message to servlet log file?

  1. log(String msg)
  2. log(int code, String msg)
  3. log(String msg, Throwable t)
  4. log(int code, String msg, Throwable t)

20 . Which tag is used in web.xml to mark a web application to be suitable for running between multiple systems?

  1. multiple
  2. distributable
  3. resource-ref
  4. transferrable
  5. splitable

21 . Which of the following are VALID servlet error attributes?

  1. javax.servet.error.status_code
  2. javax.servet.error.exception
  3. javax.servet.error.uri
  4. javax.servet.error.message
  5. javax.servet.error.query

22. Which statement is TRUE about the following jsp code snippet?

[code]
<%
String theKey = "key";
String theValue = "value";
session.removeAttribute(theKey); //1
%>

session.setAttribute("<%= theKey %>",
"<%= theValue %>"); //2

session.getAttribute("<%= theKey %>"); //3

<%= session.getAttribute(theKey) %> //4
[/code]

Choose the one below:

  1. The code compiles but might have runtime NullPointerException at //1
  2. There will have compilation error at //2 and //3
  3. There will have output as null at //4
  4. There will have output as theValue at //4

23 . Which of the following are VALID taglib configuration?

[code]
1. <taglib>
…
<tag>
<name>myTag</name>
<tag-class>MyTag</tag-class>
</tag>
…
</taglib>

2. <taglib>
…
<tag>
<name>myTag</name>
<tag-class>MyTag</tag-class>
<body-content>SERVLET</body-content>
</tag>
…
</taglib>

3. <taglib>
…
<tag>
<name>myTag</name>
<tag-class>MyTag</tag-class>
<attribute>
<name>name</name>
</attribute>
</tag>
…
</taglib>

4. <taglib>
…
<tag>
<name>myTag</name>
<tei-class>MyTagInfo</tei-class>
<body-content>JSP</body-content>
</tag>
…
</taglib>

5. <taglib>
…
<tag>
<name>myTag</name>
<tag-class>MyTag</tag-class>
<tei-class>MyTagInfo</tei-class>
<body-content>JSP</body-content>
<attribute>
<name>name</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
<type>java.lang.String</type>
</attribute>
</tag>
…
</taglib>
[/code]

Choose the one below:

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5

24 . Which of the following statement is FALSE regarding JSP page directive attributes default value?

  1. The session attribute has default value as true
  2. The buffer attribute has default value as 8kb
  3. The autoflush attribute has default value as false
  4. The isThreadSafe attribute has default value as true
  5. The isErrorPage attribute has default value as false
  6. The pageEncoding attribute has default value as ISO-8859-1

25 . Which of the following deployment descriptor tags are used for context level parameter initialization?

  1. param-name
  2. context-name
  3. context-param
  4. param-value
  5. context-value
  6. context-attrib

26 . What will be the output?

[code lang=”java”]
// Calling servlet:

public void doGet(HttpServletRequest req,
HttpServletResponse res) throws ServletException, IOException
{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<HTML><BODY>");
out.println("I am calling others!");
RequestDispatcher rd= req.getRequestDispatcher("/MyServlet");
rd.include(req, res);
out.println("</BODY></HTML>");
out.close();
}

// Target servlet:

protected void doGet(HttpServletRequest req,
HttpServletResponse res) throws ServletException, IOException
{
PrintWriter out = res.getWriter();
out.println("I am called by others!");
[/code]

Choose the one below:

  1. “I am calling others!”
  2. “I am called by others!”
  3. Both “I am calling others!” and “I am called by others!”
  4. An IllegalStateException is thrown
  5. An IOException is thrown

27 . Which statement is NOT true about the SingleThreadModel interface?

  1. By implementing this interface it ensures that servlets handle only one
  2. If a servlet implements this interface, no two threads will execute concurrently in the servlet’s service method
  3. This interface has no methods
  4. The servlet container will ensure there will be only one instance of the servlet at a time if the servlet implements this interface
  5. Class variables are not protected by this interface, but instance variables are protected

28 . Which of the following method is called upon the initialization of a servlet context?

  1. contextInitializing(ServletContextEvent e)
  2. contextInitial(ServletContext e)
  3. contextInitialize(ServletContext e)
  4. contextInitialize(ServletContextEvent e)
  5. contextInitialized(ServletContextEvent e)

29 . Which of the following statements are TRUE?

  1. XML equivalent for JSP expression <%= expression %> is <jsp:expression>expression</jsp:expression>
  2. XML equivalent for JSP scriptlet <% scriptlet %> is <jsp:scriptlet>scriptlet</jsp:scriptlet>
  3. XML equivalent for JSP declaration <%! declaration %> is <jsp:declaration>declaration</jsp:declaration>.
  4. XML equivalent for JSP include directive <%@ include file=”url” %> is <jsp:include file=”url”/>, where url must be relative
  5. XML equivalent for JSP page directive <%@ page buffer=”16kb” %> is <jsp:page buffer=”16kb”/>

30 . Please select Correct JSP useBean declaration methods?

  1. <jsp:useBean id=”user” beanName=”TestUser” type=”com.test.model.User” />
  2. <jsp:useBean id=”user” beanName=”TestUser” class=”com.test.model.User” />
  3. <jsp:useBean beanName=”TestUser” class=”com.test.model.User” />
  4. <jsp:useBean beanName=”TestUser” class=”com.test.model.User” />
  5. <jsp:useBean id=”user” type=”com.test.model.User” />

31 . Which statement is TRUE regarding the following code?

[code lang=”java”]
import javax.servlet.*;
import javax.servlet.http.*;

public class MyHttpServlet extends HttpServlet
implements SingleThreadModel {

StringBuffer bufferOne = new StringBuffer(); //1

static StringBuffer bufferTwo = new StringBuffer(); //2

protected void doGet(HttpServletRequest req, //3
HttpServletResponse res) throws java.io.IOException{

HttpSession session = req.getSession(); //4

res.setContentType("text/html");
java.io.PrintWriter out = res.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>This is my servlet!</title>");
out.println("</head>");
out.println("<body>");
out.println("</body>");
out.println("</html>");
out.close();
}
[/code]

Choose the one below:

  1. Variable bufferOne at //1 is NOT thread-safe
  2. Variable bufferTwo at //2 is NOT thread-safe
  3. Both A and B
  4. Variable req at //3 is NOT thread-safe
  5. Variable session at //4 is NOT thread-safe
  6. Both D and E

32 . Select sample web application file listing with appropriate directory structure?

[code]
1. index.html
/login.jsp
/images/logo.gif
/WEB-INF/web.xml
/WEB-INF/lib/basic.jar
/WEB-INF/classes/Test.class

2. /index.html
/login.jsp
/images/logo.gif
/WEB-INF/web.xml
/WEB-INF/jar/basic.jar
/WEB-INF/classes/Test.class

3. /index.html
/login.jsp
/images/logo.gif
/WEB-INF/web.xml
/WEB-INF/classes/basic.jar
/WEB-INF/classes/Test.class

4. /index.html
/login.jsp
/images/logo.gif
/META-INF/web.xml
/WEB-INF/jar/basic.jar
/WEB-INF/classes/Test.class

5. /index.html
/login.jsp
/images/logo.gif
/META-INF/web.xml
/WEB-INF/lib/basic.jar
/WEB-INF/classes/Test.class

6. index.html
/images/logo.gif
/WEB-INF/web.xml
/WEB-INF/jsp/login.jsp
/WEB-INF/lib/basic.jar
/WEB-INF/classes/Test.class
[/code]

Choose the one below:

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6

33 . Which of the following data element will definitely be thread-safe?

  1. Local variables
  2. Instance variables
  3. Static variables
  4. Class variables
  5. Context attributes

34 . Select the correct order that JSP methods are invoked by servlet container?

  1. jspInit(), jspService(), jspDestroy()
  2. jspInit(), _jspService(), jspDestroy()
  3. _jspInit(), jspService(), _jspDestroy()
  4. _jspInit(), _jspService(), _jspDestroy()

35 . Which of the following element is not included in a URL?

  1. Client ip
  2. Protocol
  3. Server Name
  4. Query string
  5. Port name

36 . Which of the following listeners is notified when a session is initialized?

  1. HttpSessionBindingListener
  2. SessionBindingListener
  3. HttpSessionListener
  4. HttpSessionListener
  5. HttpSessionChangedListener

37 . Which of the following best describes the life cycle of a JSP?

[code]
1. JSP page is translated into a servlet code
Servlet code is compiled
Servlet is loaded into memory
Servlet instance is created

2. JSP page is translated into a servlet code
Servlet is loaded into memory
Servlet code is compiled
Servlet instance is created

3. JSP is compiled
JSP is translated into a servlet code
Servlet is loaded into memory
Servlet instance is created

4. JSP is loaded into memory
Servlet code is compiled
Servlet instance is created
Servlet is loaded into memory

5. JSP page is translated into a servlet code
Servlet code is compiled
Servlet instance is created
Servlet is loaded into memory
[/code]

Choose the one below:

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5

38 . Please identify the three methods declared in javax.servlet.Filter?

  1. service
  2. init
  3. destroy
  4. filter
  5. doFilter

39 . Which of the following deployment descriptor segments are VALID for security-related configuration of a web application?

[code]
1. <login-config>
<auth-method>FORM</auth-method>
<login-config>
<form-login-page>/login.jsp</form-login-page>
<form-error-page>/error.jsp</form-error-page>
</login-config>
</login-config>

2. <security-role>
<description>My description.</description>
<role-name>Manager</role-name>
</security-role>

3. <security-constraint>
<web-resource-collection>
<web-resource-name>SecureStuff</web-resource-name>
<url-mapping>/servlet/secure</url-mapping>
<http-method>POST</http-method>
</web-resource-collection>
</security-constraint>

4. <security-constraint>
<auth-constraint>
<role-name>Broker</role-name>
</auth-constraint>
</security-constraint>

5. <security-constraint>
<web-resource-collection>
<web-resource-name>SecureStuff</web-resource-name>
</web-resource-collection>
<auth-constraint>
<role-name>Broker</role-name>
</auth-constraint>
</security-constraint>
[/code]

Choose the one below:

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5

40 . Based on the following information, please construct the full path for the servlet?

[code]
docbase = c:/temp/
context path = /test
alias name = MyMail
servlet-name = com.jiris.common.util.MailServlet
url-pattern = /mail/*
[/code]

Choose the one below:

  1. c:/temp/mail/com/jiris/common/util/MailServlet.class
  2. c:/temp/test/com/jiris/common/util/MailServlet.class
  3. c:/temp/mail/test/com/jiris/common/util/MailServlet.class
  4. c:/temp/test/mail/com/jiris/common/util/MailServlet.class

41 . The ServletContext object are accessible from which of the following objects?

  1. HttpServlet
  2. GenericServlet
  3. HttpSession
  4. ServletConfig
  5. ServletResponse

42 . Which of the following method is used to store object into a request object?

  1. addAttribute(String name, String obj)
  2. putAttribute(String name, Object obj)
  3. setAttribute(String name, String obj)
  4. setAttribute(String name, Object obj)
  5. addObject(String name, Object obj)

43 . Which request method will be invoked for the following code?

[code lang=”html”]
<html>
<body>
<form action=´/servlet/comment´>
<p>Please provide your comment here:</p>
<input type=´text´ size=´40´ name=´Comment´>
<input type=´submit´ value=´Submit´>
</form>
</body>
</html>
[/code]

Choose the one below:

  1. GET
  2. POST
  3. HEAD
  4. TRACE
  5. PUT

44 . Which of the following method might be invoked more than one time?

  1. doStartTag()
  2. doInitBody()
  3. doAfterBody()
  4. doEndTag()

45 . Which of the following methods are used to send an error page to the client?

  1. log(String msg)
  2. log(String msg, Throwable t)
  3. sendError(int code)
  4. sendError(int code, String msg)
  5. sendError(int code, String msg, Throwable t)

46 . Which of the following requests should be performed by using a POST method?

  1. Inserting a record into a database
  2. Accessing a static page
  3. Retrieving an image
  4. Sending credit card number
  5. Searching record in a database

47 . Which of the following are Correct ways to define inactive period of 5 minutes of a session before the server invalidates it?

  1. <session-timeout>5</session-timeout>
  2. <session-timeout>300</session-timeout>
  3. session.setMaxInactiveInterval(5);
  4. session.setMaxInactiveInterval(300);
  5. session.invalidate(5);

48 . Which are the two mandatory attributes for JSP taglib directive?

  1. uri
  2. id
  3. name
  4. prefix
  5. value
  6. location

49 . A session can be invalidated by which of the following?

  1. After a default period of inactivity, say 30 minutes
  2. Client side user closes the browser
  3. After a specified period of inactivity, say 10 minutes
  4. Client side user machine crashes
  5. Explicitly invalidate a session through method calls

50 . What is the method declaration for the method used in the HttpServlet class that handles the HTTP GET request?

  1. doGet(ServletRequest req, ServletResponse res)
  2. getPage(ServletRequest req, ServletResponse res)
  3. doGet(HttpServletRequest req, HttpServletResponse res)
  4. service(HttpServletRequest req, HttpServletResponse res)

Answers

1 : 3 is correct.
Explanation: To notify the container to reevaluate the custom tag’s body, you must return a value of IterationTag.EVAL_BODY_AGAIN in the doAfterBody() method.

2 : 2,3 & 4 is correct.
Explanation: jsp:bean declares the use of a JavaBean instance in a JSP page.
jsp:plugin instructs the JSP engine to generate appropriate HTML code for embedding applets on a web page.
Custom tags (taglibs) allow user-defined actions to be created.
Answer 1 is incorrect because the action JSP tag provides request-time instructions to the JSP engine.
Standard action types : jsp:include, jsp:forward, jsp:useBean, jsp:setProperty, jsp:getProperty, jsp:plugin

3 : 2 & 4 is correct.
Explanation: You can use either forward(…) or include(…) method to pass the request to another servlet to handle. While for forward(…), the control is passing to target servlet, for include(…), the control is still with the current servlet.

4 : 3 & 5 is correct.
Explanation: You need to override the service() method when you extends GenericServlet.
You need to call super.init(config) if you override this method.

5 : 2 is correct.
Explanation: A Data Access Object pattern is used to encapsulate database access functions. By putting database-specific SQL code into a separate layer as DAO layer, it is easy to modify it without affecting business logic layer, thus increase code manageability.

6 : 1 & 2 is correct.

7 : 3 & 5 is correct.

8 : 4 is correct.

9 : Client-Cert.
Explanation: The correct answer is CLIENT-CERT which stands for client certificate. It requires the client to provide a digital certificate containing information about the issuer, signature, serial number, key type, etc

10 : 2 is correct.

11 : 1,3 & 4 is correct.

12 : 3 is correct.

13 : 2,3,4 & 5 is correct.

14 : 3 is correct.

15 : 1 & 4 is correct.

16 : 1 is correct.

17 : 1,3 & 4 is correct.

18 : 3 is correct.

19 : 1 & 3 is correct.

20 : 2 is correct.

21 : 1,2 & 4 is correct.

22 : 3 is correct.

23 : 1,3 & 5 is correct.

24 : 3 is correct.

25 : 1,3 & 4 is correct.

26 : 3 is correct.

27 : 4 is correct.

28 : 5 is correct.

29 : 1,2 & 3 is correct.

30 : 1,4 & 5 is correct.

31 : 2 is correct.

32 : 1 & 6 is correct.

33 : 1 is correct.

34 : 2 is correct.

35 : 1 is correct.

36 : 3 is correct.

37 : 1 is correct.

38 : 2,3 & 5 is correct.

39 : 2 & 5 is correct.

40 : 2 is correct.

41 : 1,3 & 4 is correct.

42 : 4 is correct.

43 : 1 is correct.

44 : 3 is correct.

45 : 3 & 4 is correct.

46 : 1 & 4 is correct.

47 : 1 & 4 is correct.

48 : 1 & 4 is correct.

49 : 1,3 & 5 is correct.

50 : 3 is correct.

Filed Under: Certifications Tagged With: OCEJWCD, OCEJWCD 6

OCEJWCD 6 Mock Exam – 5

February 7, 2014 by Krishna Srinivasan Leave a Comment

1 . Assume that the following header is present in a request sent to a servlet:

[code]
Accept: image/gif, image/jpeg, image/bmp
[/code]

What will be returned when the servlet code calls request.getHeader(“Accept”)?

Choose the one below:

  1. A Header object containing, name as “Accept” and value as “image/gif”
  2. A Header object containing, name as “Accept” and value as “image/gif, image/jpeg, image/bmp”
  3. A String array containing “image/gif””
  4. A String containing “image/gif, image/jpeg, image/bmp”
  5. A String array containing “image/gif”, “image/jpeg”, image/bmp”

2 . You need to send large amount of binary data from the browser to a servlet to be processed?
(Say, you want to attach a file while sending email through a web based system)
What HTTP method would you use?

  1. GET
  2. POST
  3. HEAD
  4. HIDDEN
  5. PUT

3 . Which of the following is a possible way to configure an HttpSessionAttributeListener?

  1. By calling HttpSession.addAttributeListener(…)
  2. By calling HttpSession.addHttpSessionAttributeListener(…)
  3. An object of a class implementing this interface is automatically configured when it is added to the session
  4. None of these

4 . Servlet Container calls the init method on a servlet instance…?

  1. For each request to the servlet
  2. For each request to the servlet that causes a new session to be created
  3. For each request to the servlet that causes a new thread to be created
  4. Only once in the life time of the servlet instance
  5. If the request is from the user whose session has expired
  6. Initialy when the servlet instance is create and then at request time if the request is from the user whose session has expired

5 . Which of the following methods may be called on a custom tag handler that implements IterationTag interface?

  1. doStartTag
  2. doBodyTag
  3. doAfterBody
  4. doInitBody
  5. doEvalBody

6 . Which of the following elements of web.xml defines a mapping between a servlet and a URL pattern?

  1. mapping
  2. servlet-url
  3. url_mapping
  4. url_pattern
  5. servlet-mapping

7 . Following is the code for doGet() method of TestServlet. Which of the given statements about it are correct?

[code lang=”java”]
public void doGet(HttpServletRequest req, HttpServletResponse res)

{

try

{

RequestDispatcher rd = this.getServletContext().getRequestDispatcher("Login.jsp"); // 1

rd.forward(req, res); // 2

}

catch(Exception e)

{

e.printStackTrace();

}

}
[/code]

Choose the one below:

  1. This will not compile
  2. This will compile but will not work as expected
  3. This code will work just fine
  4. It will compile but not work properly if //1 is replaced with:
    RequestDispatcher rd = req.getRequestDispatcher(“Login.jsp”);
  5. It will compile and will work properly if //1 is replaced with:
    RequestDispatcher rd = req.getRequestDispatcher(“Login.jsp”);

8 . Consider the web.xml snippet shown in the exhibit? Now consider the code for a jsp file named unprotected.jsp:

[code lang=”html”]
<html>

<body>

<jsp:include page="/jsp/protected.jsp" />

</body>

</html>
[/code]

Which of the following statements hold true when unprotected.jsp is requested by an unauthorized user?

[code]
<web-app>

…

<security-constraint>

<web-resource-collection>

<web-resource-name>test</web-resource-name>

<url-pattern>/jsp/protected.jsp</url-pattern>

</web-resource-collection>

<auth-constraint>

<role-name>manager</role-name>

</auth-constraint>

</security-constraint>

…

</web-app>
[/code]

Choose the one below:

  1. The user will be prompted to enter user name and password
  2. An exception will be thrown
  3. protected.jsp will be executed but it’s output will not be included in the response
  4. The call to include will be ignored
  5. None of these

9 . Which of the following JSP elements can have a <jsp:param …> element in its body?

  1. <jsp:include …>
  2. <%@ include …>
  3. <jsp:directive.include …/>
  4. <%@ forward …>
  5. <jsp:action …>

10 . Which of the following implicit variables should be used by a jsp page to access a resource and to forward a request to another jsp page?

  1. pageContext and config
  2. application and config
  3. config and pageContext
  4. application for both
  5. config for both

11 . In which of the following situations will a session be definitely invalidated?

  1. The container is shutdown and brought up again
  2. No request comes from the client for more than “session timeout” period
  3. A servlet explicitly calls invalidate() on a session object
  4. A servlet explicitly calls invalidate() on a session object

12 . Your jsp page uses classes from java.util package. Which of the following statement would allow you to import the package?

  1. <%@import java.util.* %>
  2. <%import=”java.util.*”@%>
  3. <%@ page import=”java.util.*”%>
  4. <%@ page java=”java.util.*”@%>
  5. <%@ page import=”java.util.*”@%>

13 . Consider the following contents for two JSP files:

[code lang=”html”]
In file companyhome.jsp:

<html><body>

Welcome to ABC Corp!

<%@ page errorPage="simpleerrorhandler.jsp" %>

<%@ include file="companynews.jsp" %>

</body></html>
[/code]
[code]
In file companynews.jsp:

<%@ page errorPage="advancederrorhandler.jsp" %>

<h3>Todays News</h3>
[/code]

Which of the following statements are correct?

Choose the one below:

  1. When companyhome.jsp is requested, the output will contain “welcome…” as well as “Todays News”
  2. companyhome.jsp will not compile
  3. companynews.jsp will not compile
  4. Both the files will compile but will throw an exception at runtime
  5. None of these

14 . Which method of RegisterServlet will be called when the user clicks on “Submit” button for the following form?
Assume that RegisterServlet

[code lang=”html”]
<html>

<body>

<form action="/myapp/RegisterServlet">

<input type="text" name="method" value="POST">

<input type="text" name="name">

<input type="password" name="password">

<input type="submit" value="POST">

</form>

</body>

</html>
[/code]

Choose the one below:

  1. servicePost(HttpRequest, HttpResponse);
  2. doPOST(HttpRequest, HttpResponse);
  3. post(HttpRequest, HttpResponse);
  4. doPost(HttpRequest, HttpResponse);
  5. None of the above

15 . You are building the server side of an application and you are finalizing the interfaces that you will provide to the client side. But you have not yet decided whether the business rules will be fully implemented as stored procedures or in the java code. Which design pattern you should use to mitigate this concern?

  1. Model View Controller
  2. Data Access Object
  3. Business Delegate
  4. Facade
  5. Transfer Object

16 . Which of the following XML frgaments correctly define the <login-config> element of web.xml?

[code]
1. <login-config>

<auth-method>CLIENT-CERT</auth-method>

<realm-name>test</realm-name>

</login-config>

2. <login-config>

<auth-method>CLIENT-CERT</auth-method>

<realm-name>test</realm-name>

<form-login-config>

<form-login-page>/jsp/login.jsp</form-login-page>

<form-error-page>/jsp/error.jsp</form-error-page>

</form-login-config>

</login-config>

3. <login-config>

<auth-method>FORM</auth-method>

<realm-name>test</realm-name>

<form-login-config>

<form-login-page>/jsp/login.jsp</form-login-page>

<form-error-page>/jsp/error.jsp</form-error-page>

</form-login-config>

</login-config>

4. <login-config>

<auth-method>FORM</auth-method>

<realm-name>test</realm-name>

</login-config>

5. <login-config>

<auth-method>SECURE</auth-method>

<realm-name>test</realm-name>

</login-config>
[/code]

Choose the one below:

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5

17 . What are the following deployment descriptor elements used for
<login-config> <security-constraint> <security-role>?

  1. Authorization
  2. Authentication
  3. Privacy
  4. Authentication and Authorization
  5. Data integrity

18 . You want to do some calculations within the object whenever it is added to the session. What would you do to accomplish this?

  1. Make the class of the object implement HttpSessionBindingListener
  2. Configure a HttpSessionAttributeListener in deployment descriptor
  3. Make the class of the object implement HttpSessionListener
  4. Configure a HttpSessionActivationListener in deployment descriptor
  5. Only way is to configure a HttpSessionAttributeListener in the deployment descriptor

19 . GET method is not suitable for which of the following operations?

  1. Retrieving an image
  2. Retrieving a zip file
  3. Submitting a form not containing login or other critcal information
  4. Submitting a login form
  5. Updating a database

20 . In the case of JSP pages, what is the type of the implicit variable ‘out’?

  1. OutputStream
  2. PrintStream
  3. PrintWriter
  4. JspWriter
  5. DataOutputStream

21 . Match the following?

[code]
Comment
directive
declaration
scriptlet
Custom tag
expression
[/code]

Choose the one below:

  1. <tags:simple name=’bob’ />
  2. <%=request.getParameter(“name”)%>
  3. <%request.getParameter(“name”);%>
  4. <jsp:directive.include file=’hello.jsp’ />
  5. <%– String x = “123” –%>
  6. <%!String x = “123”; %>

22 . Consider the following tag occuring in a JSP page:

[code]
<%@page import="java.util.*"%>;
[/code]

Which of the following is the XML equivalent of the above tag?

Choose the one below:

  1. <directive.page import=”java.util.*”/>
  2. <page import=”java.util.*”/>
  3. <%jsp:directive.page import=”java.util.*”%>
  4. <sp:page import=”java.util.*”/>
  5. <jsp:directive.page import=”java.util.*”/>

23 . Your servlet may throw IOException while processing a request.You want to define an error page in your deployment descriptor so that whenever IOException is thrown,this page is serviced to the browser. Which of the following XML fragments correctly specify the mapping?

[code]
1. <error-page>

<exception>java.io.IOException</exception>

<location>/html/Test.html</location>

</error-page>

2. <error-page>

<exception-class>java.io.IOException</exception-class>

<location>/html/Test.html</location>

</error-page>

3. <error-page>

<exception-type>java.io.IOException</exception-type>

<page-location>/html/Test.html</page-location>

</error-page>

4. <error-page>

<exception-type>java.io.IOException</exception-type>

<location>/Enthuse/html/Test.html</location>

</error-page>

5. <exception>

<exception-type>java.io.IOException</exception-type>

<location>/Enthuse/html/Test.html</location>

</exception>
[/code]

Choose the one below:

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5

24 . How can you ensure the continuity of the session while using HttpServletResponse.sendRedirect() method when cookies are not supported by the client?

  1. By using hidden parameters
  2. By enconding the redirect path with HttpServletResponse.encodeRedirectURL() method
  3. By using HttpSession.encodeURL() method
  4. By using HttpServletRequest.encodeURL() method
  5. By using HttpServletResponse.encodeURL() method

25 . Which of the following XML fragments correctly defines a role named “manager” in web.xml?

[code]
1. <security-role>manager</security-role>

2. <security-role rolename=manager></security-role>

3. <security>

<role-name>manager</role-name>

</security>

4. <security-role>

<role-name>manager</role-name>

</security-role>
[/code]

Choose the one below:

  1. 1
  2. 2
  3. 3
  4. 4

26 . Which of the following methods of HttpServletRequest can be used to retrieve the parameter values sent from the browser?

  1. getParameter(String name);
  2. getParameter(String name, String defaultValue);
  3. getParameterNames();
  4. getParameterValues(String name);
  5. getParameters(String name);

27 . Consider the code for the web.xml for a web application (See exhibit)?
Assume that a request: http://localhost:8080/test/aaa/abc.a is sent to this web application named test?

[code lang=”xml”]
<?xml version="1.0" encoding="ISO-8859-1"?>

<!– Assume that DOCTYPE is valid –>

<!DOCTYPE web-app

PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.4//EN"

"http://java.sun.com/dtd/web-app_2_4.dtd">

<web-app>

<servlet>

<servlet-name>TestServlet</servlet-name>

<jsp-file>/requestinfo.jsp</jsp-file>

</servlet>

<servlet-mapping>

<servlet-name>TestServlet</servlet-name>

<url-pattern>*.a</url-pattern>

</servlet-mapping>

</web-app>
[/code]

Choose the one below:

  1. Path Info of the request will be /aaa/abc.a
  2. RequestPath of this request will be /test//aaa/abc.a
  3. ContextPath of this request will be /test/aaa
  4. This request will be serviced by requestinfo.jsp
  5. None of these

28 . You are using a tag library with prefix “sequenceengine” which supports a tag named “fib”. This tag expects a parameter named “limit” of type int. Which of the following is a correct use of this tag?

  1. <sequenceengine:fib>20</sequenceengine:fib>
  2. <fib:sequenceengine>20</fib:sequenceengine>
  3. <sequenceengine:fib attribute-name=”limit” attribute-value=”20″></sequenceengine:fib>
  4. <sequenceengine:fib limit=”20″></sequenceengine:fib>
  5. <fib:sequenceengine limit=”20″></fib:sequenceengine>

29 . How can you redirect the request from a servlet to another resource if the servlet encounters an exception?

  1. This cannot be done unless the exception is caught in the servlet
  2. By specifying a mapping between exception class and the resource in web.xml
  3. This can be done only if the exception is a subclass of javax.servlet.ServletException
  4. This can be done even if the exact class of the exception is not known at compile time

30 . Which of the given options correctly declare a useBean tag?

  1. <jsp:useBean id=”user” class=”myco.util.User” />
  2. <jsp:useBean id=”user” type=”myco.interfaces.IUser” />
  3. <jsp:useBean name=”user” class=”myco.util.User” />
  4. <jsp:useBean id=”user” beanName=”myco.User” class=”myco.util.User” />
  5. <jsp:useBean id=”user” beanName=”myco.User” type=”myco.interfaces.IUser” />

Answers

1 : 4 is correct.

2 : 2 is correct.

3 : 4 is correct.

4 : 4 is correct.

5 : 1 & 3 is correct.

6 : 5 is correct.

7 : 3 & 5 is correct.

8 : 5 is correct.

9 : 1 is correct.

10 : 4 is correct.

11 : 2,3 & 4 is correct.

12 : 3 is correct.

13 : 2 is correct.

14 : 5 is correct.

15 : 3 is correct.

16 : 1,2 & 3 is correct.

17 : 4 is correct.

18 : 1 is correct.

19 : 4 & 5 is correct.

20 : 4 is correct.

21 :
comment – <%– String x = “123” –%>
directive – <jsp:directive.include file=’hello.jsp’ />
declaration – <%!String x = “123”; %>
scriptlet – <%request.getParameter(“name”);%>
custom tag – <tags:simple name=’bob’ />
expression – <%=request.getParameter(“name”)%>
22 : 5 is correct.

23 : 4 is correct.

24 : 2 is correct.

25 : 4 is correct.

26 : 1 & 4 is correct.

27 : 4 is correct.

28 : 4 is correct.

29 : 2 & 4 is correct.

30 : 1,2 & 5 is correct.

Filed Under: Certifications Tagged With: OCEJWCD, OCEJWCD 6

OCEJWCD 6 Mock Exam – 4

February 7, 2014 by Krishna Srinivasan

1 . Consider the following web.xml code:

[code lang=”xml”]
<servlet>

<servlet-name>BankServlet</servlet-name>

<servlet-class>com.abc.bankapp.BankServlet</servlet-class>

<security-role-ref>

<role-name>manager</role-name>

<role-link>supervisor</role-link>

</security-role-ref>

</servlet>
[/code]

Which of the following statements are correct?

Choose the one below:

  1. The servlet code should use “manager” as a parameter in request.isUserInRole() method
  2. The servlet code can use “manager” or “supervisor” as a parameter in request.isUserInRole() method
  3. The servlet code should use”supervisor” as a parameter in request.isUserInRole() method
  4. The role of “manager” must be defined in the servlet container
  5. None of these

2 . You are designing a complex webapp that uses multi tier architecture.The application must provide interfaces for HTML as well as XML and should be maintainable.Which design pattern would you use?

  1. Data Access Object
  2. Business Deligate
  3. MVC
  4. Remote Method Invocation
  5. Transfer Object

3 . Which of the following directives are applicable ONLY for tag files?

  1. attribute
  2. variable
  3. page
  4. include
  5. import
  6. tag

4 . Which of the following are correct about FORM based authentication mechanism?

  1. HTML FORM is used to capture the username and password of the user
  2. Password is transmitted as plain text
  3. Password is transmitted in an encrypted form
  4. Password is transmitted either in encrypted text or in plain text depending on the browser
  5. This mechanism can be used over HTTPS

5 . Which pattern allows you to replace the presentation logic without much impact on the data representation?

  1. Model View Controller
  2. Business Delegate
  3. Transfer Object
  4. Data Access Object
  5. Bimodal DataAccess

6 . Identify the elements that help describe the attribute characteristics of a JSP custom tag in a TLD file?

  1. value
  2. name
  3. description
  4. rtexprvalue
  5. class

7 . Select the correct return types for ServletContext.getResource() and ServletContext.getResourceAsStream() methods?

  1. java.io.Resource and java.io.InputStream
  2. java.io.Resource and java.io.BufferedInputStream
  3. java.net.URL and java.io.InputStream
  4. java.io.File and java.io.InputStream
  5. java.net.URL and java.io.FileInputStream

8 . What will be the output?

[code lang=”html”]
<html>

<body>

<% String a = "aaa"; %>

<%! String a = "AAA"; %>

<% String b = "bbb"; %>

<%! String b = "BBB"; %>

<% out.println(a+b); %>

</body>

</html>
[/code]

Choose the one below:

  1. aaabbb
  2. aaaBBB
  3. AAAbbb
  4. AAABBB
  5. Compilation error!

9 . Which of the following are valid values for the <transport-guarantee> element?

  1. CONFIDENTIAL
  2. INTEGRAL
  3. SECURE
  4. ENCRYPTED
  5. NONE

10 . Write the parent element of <session-timeout> element?

11 . Consider the tag handler class shown in exhibit.What will be printed when the above tag is used as follows in a jsp page?

[code lang=”java”]
Hello <mylib:mytag> World!</mylib:mytag>

public class MyTag extends TagSupport

{

public int doAfterBody()

{

try

{

pageContext.getOut().println("In doAfterBody()");

}

catch(Exception e)

{

}

return SKIP_BODY;

}

}
[/code]

Choose the one below:

  1. Hello
  2. Hello World!
  3. Hello In doAfterBody() World!
  4. Hello In doAfterBody()
  5. None of the above

12 . Which of the following HTTP protocol methods is eligible to produce unintended side effects upon multiple identical invocations beyond those caused by single invocation?

  1. GET
  2. POST
  3. HEAD
  4. PUT
  5. OPTIONS

13 . Which method of ServletResponse would you use to set its content type?

  1. setParameter
  2. setHeader
  3. setAttribute
  4. setContentType
  5. None of the above

14 .

[code]
<jsp:useBean id="mybean" beanName="my.app.MyBean" class="my.app.MyBean" />
[/code]

is a valid useBean declaration?

Choose the one below:

  1. True
  2. False

15 . Which of the following lines can be used to retrieve a servlet initialization parameter “dbname” from the init() method of a servlet?

[code lang=”java”]
public void init()

{

String dbname = //1 : Insert line here

}
[/code]

Choose the one below:

  1. getServletConfig().getParameter(“dbname”);
  2. getServletConfig().getInitParameter(“dbname”);
  3. getServletContext().getInitParameter(“dbname”);
  4. getInitParameter(“dbname”);
  5. getInitParameterValue(“dbname”);

16 . Consider the following description of a tag in a TLD?

[code]
<tag>

<name>SmilyTag</name>

<tag-class>com.enthuware.ctags.SmilyTag</tag-class>

<description>

Replaces emoticons such as :), :D, and 🙁 with images.

</description>

<body-content>tagdependent</body-content>

<attribute>

<name>name</name>

<required>false</required>

<rtexprvalue>true</rtexprvalue>

</attribute>

</tag>
[/code]

Which of the following statements regarding the above tag are correct?

Choose the one below:

  1. It is an empty tag
  2. It may be used as an empty tag
  3. It must have a body
  4. It must implement BodyTag interface
  5. It may take an attribute named ‘name’.But if present,its value must be dynamic

17 . Which of the following jsp fragments will print all the parameters and their values present in a request?

[code]
1. <% Enumeration enum = request.getParameterNames();

while(enum.hasMoreElements()) {

Object obj = enum.nextElement();

out.println(request.getParameter(obj));

} %>

2. <% Enumeration enum = request.getParameters();

while(enum.hasMoreElements()) {

String obj = (String) enum.nextElement();

out.println(request.getParameter(obj));

} %>

3. <% Enumeration enum = request.getParameterNames();

while(enum.hasMoreElements()) {

String obj = (String) enum.nextElement();

out.println(request.getParameter(obj));

} %>

4. <% Enumeration enum = request.getParameterNames();

while(enum.hasMoreElements()) {

Object obj = enum.nextElement(); %>

<%=request.getParameter(obj); %>

<% } %>

5. <% Enumeration enum = request.getParameterNames();

while(enum.hasMoreElements()) {

String obj = (String) enum.nextElement(); %>

<%=request.getParameter(obj)%>

<% } %>
[/code]

Choose the one below:

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5

18 . Which of the following statements are valid JSP directive?

  1. <%! int k = 10 %>
  2. <% int k = 10; %>
  3. <%=somevariable%>
  4. <%@ taglib uri=”http://www.abc.com/tags/util” prefix=”util” %>
  5. <%@ page language=”java” import=”com.abc.*”%>

19 . How can you ensure the continuity of the session while using HttpServletResponse.sendRedirect() method when cookies are not supported by the client?

  1. By using hidden parameters
  2. By enconding the redirect path with HttpServletResponse.encodeRedirectURL() method
  3. By using HttpSession.encodeURL() method
  4. By using HttpServletRequest.encodeURL() method
  5. By using HttpServletResponse.encodeURL() method

20 . Which of the following are valid implicit variables in a JSP page?

  1. error
  2. page
  3. this
  4. root
  5. context

21 . A Tag Handler implements BodyTag interface.How many times its doAfterBody method may be called?

  1. BodyTag does not support doAfterBody
  2. 0
  3. 1
  4. 0 or 1
  5. Any number of times

22 . You have configured a listener class (see exhibit) in web.xml of a web application?
Now, consider the following code for the doGet() method of a servlet for the same web application?

[code lang=”java”]
public void doGet(HttpServletRequest req, HttpServletResponse res)

{

System.out.println(this.getServletContext().getAttribute("key"); //2

}
[/code]

Which option can be inserted at //1 in the listener code so that servlet code at //2 prints 100?

[code lang=”java”]
import javax.servlet.*;

public class MyListener implements ServletContextListener

{

public void contextInitialized(ServletContextEvent sce)

{

Integer key = new Integer(100);

// 1 Insert code here.

}

public void contextDestroyed(ServletContextEvent sce)

{

}

}
[/code]

Choose the one below:

  1. this.setAttribute(“key”, key);
  2. this.getServletContext().setAttribute(“key”, key);
  3. this.getContext().setAttribute(“key”, key);
  4. sce.getContext().setAttribute(“key”, key);
  5. sce.getServletContext().setAttribute(“key”, key);

23 . Which of the following interfaces declares the methods jspInit() and jspDestroy()?

  1. javax.servlet.jsp.JSP
  2. javax.servlet.jsp.JspServlet
  3. javax.servlet.jsp.JspPage
  4. javax.servlet.jsp.HttpJspPage
  5. javax.servlet.jsp.HttpJspServlet

24 . Which of the following statements are correct JSP directives?

  1. <%@ page %>
  2. <%! taglib uri=”http://www.abc.com/tags/util” prefix=”util” %>
  3. <% include file=”/copyright.html”%>
  4. <%@ taglib uri=”http://www.abc.com/tags/util” prefix=”util” %>
  5. <%$ page language=”java” import=”com.abc.*”%>

25 . Which of the following classes hides the implementation details and provides a standard API to the services provided by the servlet container to a jsp page?

  1. HttpSession
  2. Servlet
  3. JspPage
  4. ServletContext
  5. PageContext

26 . Which of the following are true regarding the parameters defined using the <context-param> element of a deployment descriptor?

  1. They are thread safe
  2. They are accessible from multiple threads simultaneously and from any servlet of the web application
  3. They can be modified using the setAttribute() method
  4. They can be modified using the setParameter() method
  5. They can be modified using the setInitParameter() method

27 . How can you explicitly expunge the session object?

  1. You cannot. It can only be expunged automatically after session timeout expires
  2. By calling invalidate() on session object
  3. By calling expunge() on session object
  4. By calling delete() on session object
  5. By calling finalize() on session object

28.You have declared a useBean tag as

[code]
<jsp:useBean id="man" class="animal.Human" scope="application"/>
[/code]

In which type of object will this bean be kept?

Choose the one below:

  1. Servlet
  2. HttpSession
  3. ServletContext
  4. ServletConfig
  5. ApplicationContext

29 . Which of the following is a sensible way of sending an error page to the client in case of a business exception that extends from java.lang.Exception?

  1. Catch the exception and use RequestDispatcher to forward the request to the error page
  2. Don’t catch the exception and define the ‘exception to error-page’ mapping in web.xml
  3. Catch the exception, wrap it into ServletException and define the ‘business exception to error-page’ mapping in web.xml
  4. Catch the exception, wrap it into ServletException, and define the ‘ServletException to error-page’ mapping in web.xml
  5. Don’t do anything, the servlet container will automatically send a default error page

30 . Business delegate pattern should be used to enable communication between the JSP code and the enterprise javabeans?

Choose the one below:

  1. True
  2. False

Answers

1 : 1 is correct.

2 : 3 is correct.

3 : 1,2 & 6 is correct.

4 : 1,2 & 5 is correct.

5 : 1 is correct.

6 : 2,3 & 4 is correct.

7 : 3 is correct.

8 : 1 is correct.

9 : 1,2 & 5 is correct.

10 : session-config.

11 : 1 is correct.

12 : 2 is correct.

13 : 4 is correct.

14 : 2 is correct.

15 : 2 & 4 is correct.

16 : 2 & 4 is correct.

17 : 3 & 5 is correct.

18 : 4 & 5 is correct.

19 : 2 is correct.

20 : 2 & 3 is correct.

21 : 5 is correct.

22 : 5 is correct.

23 : 3 is correct.

24 : 1 & 4 is correct.

25 : 5 is correct.

26 : 1 & 2 is correct.

27 : 2 is correct.

28 : 3 is correct.

29 : 1 & 3 is correct.

30 : 1 is correct.

Filed Under: Certifications Tagged With: OCEJWCD, OCEJWCD 6

OCEJWCD 6 Mock Exam – 3

February 7, 2014 by Krishna Srinivasan Leave a Comment

1 . Regarding the processing of a BodyTag handler,in which of the following cases a BodyContent object will be “pushed” into the pageContext?

  1. If the doStartTag() returns EVAL_BODY_INCLUDE
  2. If the doStartTag() returns EVAL_BODY_BUFFERED
  3. If the doStartTag() returns SKIP_BODY
  4. If the doStartTag() DOES NOT return SKIP_BODY
  5. A BodyContent object it is always created and pushed no matter what doStartTag() returns

2 . Which of the following apply to Transfer Object design pattern?

  1. It increases complexity by increasing the number of remote interfaces
  2. It increases network performance by introducing one coarse grained remote call for multiple finer grained network calls
  3. It reduces network traffic by introducing one coarse grained remote call for multiple finer grained network calls
  4. It increase server throughput by utilizing the CPU better
  5. It increases design overhead due to versioning issues

3 . Which of the following deployment descriptor snippets would you use to declare the use of a tag library?

[code]
1. <tag-lib>

<uri>http://abc.net/ourlib.tld</uri>

<location>/WEB-INF/ourlib.tld</location>

</tag-lib>

2. <taglib>

<uri>http://abc.net/ourlib.tld</uri>

<location>/WEB-INF/ourlib.tld</location>

</taglib>

3. <taglib>

<taglib-uri>http://abc.net/ourlib.tld</taglib-uri>

<taglib-location>/WEB-INF/ourlib.tld</taglib-location>

</taglib>

4. <taglib>

<tagliburi>http://abc.net/ourlib.tld</uri>

<tagliblocation>/WEB-INF/ourlib.tld</location>

</taglib>

5. <taglibmap>

<uri>http://abc.net/ourlib.tld</uri>

<location>/WEB-INF/ourlib.tld</location>

</taglibmap>
[/code]

Choose the one below:

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5

4 . Which of the following design patterns is used to separate the task of writing the GUI screens and business logic?

  1. View Logic
  2. Front Controller
  3. Model View Controller
  4. Business View
  5. Business Delegate

5 . For this jsp code to compile and run which of the given options should be true?

[code]
<jsp:useBean class="com.bookstore.Book" type="java.lang.Object" id="book" />
[/code]

Choose the one below:

  1. This statement is wrong as type attribute is invalid
  2. Book must have a public no args constructor
  3. Book must have a public constructor but there is no requirement on arguments
  4. Book must have a public getInstance() method
  5. This statement will always throw an exception at runtime no matter what you do to Book class

6 . Your servlet may throw IOException while processing a request.You want to define an error page in your deployment descriptor so that whenever IOException is thrown,this page is serviced to the browser?
Which of the following XML fragments correctly specify the mapping?

[code]
1. <error-page>

<exception>java.io.IOException</exception>

<location>/html/Test.html</location>

</error-page>

2. <error-page>

<exception-class>java.io.IOException</exception-class>

<location>/html/Test.html</location>

</error-page>

3. <error-page>

<exception-type>java.io.IOException</exception-type>

<page-location>/html/Test.html</page-location>

</error-page>

4. <error-page>

<exception-type>java.io.IOException</exception-type>

<location>/Enthuse/html/Test.html</location>

</error-page>

5. <exception>

<exception-type>java.io.IOException</exception-type>

<location>/Enthuse/html/Test.html</location>

</exception>
[/code]

Choose the one below:

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5

7 . Select the tag that comes directly under the tag of a web.xml and that is used to specify a class whose object will be sent notifications when changes occur to the SevletContext?

  1. servlet-context-listener
  2. listener
  3. context-listener-class
  4. listener-class
  5. context-listener

8 . Consider the following JSP code (See exhibit)?
What will it print for the very first request to this page as well as the web application that contains this page?

[code lang=”html”]
<html><body>

<%

Integer count = (Integer) request.getSession(false).getAttribute("count");

if(count != null )

{

out.println(count);

}

else request.getSession(false).setAttribute("count", new Integer(1));

%>

Hello!

</body></html>
[/code]

Choose the one below:

  1. It will print Hello!
  2. It will print Hello and will set the count attribute in the session
  3. It will throw a NullPointerException at request time
  4. It will not compile

9. The following line of code exists in the doGet method of Servlet:

[code lang=”java”]
String sid = request.getParameter("jsessionid");
[/code]

Which of the options will retrieve the HttpSession associated with the request?
(Assume that the session has already been created.)

Choose the one below:

  1. HttpSession session = request.getSession();
  2. HttpSession session = HttpSession.getSession(sid);
  3. HttpSession session = request.getSession(sid);
  4. HttpSession session = request.getSession(true);
  5. HttpSession session = request.getSession(false);

Answers

1 : 3 is correct.

2 : 2 & 3 is correct.

3 : 3 is correct.

4 : 2 is correct.

5 : 2 is correct.

6 : 4 is correct.

7 : 2 is correct.

8 : 2 is correct.

9 : 1,4 & 5 is correct.

Filed Under: Certifications Tagged With: OCEJWCD, OCEJWCD 6

OCEJWCD 6 Mock Exam – 2

February 7, 2014 by Krishna Srinivasan Leave a Comment

1 . You are using a tag library with prefix “generator”, which supports a tag named “random”.This tag generates a random number and sets it to a variable named “value”.Which of the following will output this value in the page?

  1. <generator:random>value</generator:random>
  2. <generator:random><%=value%></generator:random>
  3. <generator:random><% int value;%> <%=value%></generator:random>
  4. <generator:random><%getParameter(“value”)%></generator:random>
  5. None of the above

2 . Which of the following pairs of HTTP method and HttpServlet class method are a valid combination for a request and the request handler method?

  1. GET – service()
  2. POST – doPost()
  3. GET – doPost()
  4. GET – doGet()
  5. POST – service()

3 . You want to get notified whenever there is a change in the attribute list of the ServletContext of your web application. Which listener interface would you implement?

  1. ServletListener
  2. ServletContextListener
  3. ServletContextAttributeListener
  4. HttpServletContextListener
  5. HttpServletListener

4 . A JSP page myerror.jsp has been invoked as a result of an exception from another JSP page. How can you access the Throwable object that refers to the exception in myerror.jsp?

  1. Using the implicit variable error
  2. Using the implicit variable request.error
  3. Using the implicit variable exception
  4. Using the implicit variable throwable
  5. None of these because the class of the implicit variable is not java.lang.Throwable

5 . Which of the following are valid return values for doStartTag() method?

  1. BodyTag.SKIP_BODY
  2. Tag.SKIP
  3. Tag.EVAL_BODY_INCLUDE
  4. Tag.EVAL_BODY_AGAIN
  5. BodyTag.EVAL_BODY_BUFFERED

6 . Which of the following statements are correct for a custom tag that can take any number of arbitrary attributes?

  1. The body-content element for the tag in the TLD file must have a value of JSP
  2. The tag handler must implement the method setAttribute(String key, String value)
  3. The tag element in the TLD file for the tag must have <dynamic-attributes>true</dynamic-attributes>
  4. The class implementing the tag must implement javax.servlet.jsp.tagext.DynamicAttributes interface
  5. Dynamic attributes cannot have request time expression values
  6. A JSP page sets a dynamic attribute using <jsp:setDynamicAttribute> action

7 . Assuming that occurs before the use of the custom tags of the tag library named utils, identify the possibly valid empty custom tag declarations. (Assume that transpose is a valid tag in the given tag library.)

  1. <util:transpose/>
  2. <util:transpose></util:transpose>
  3. <util:transpose>200</util:transpose>
  4. <taglib:util:transpose />
  5. None of the above is correct as every tag has to have a body

8 . Which of the following defines the class name of a tag in a TLD?

  1. tag-class-name
  2. tag-class
  3. class-name
  4. class

9 . What should be the value of subelement of element in a TLD file if the tag should not have any contents as its body?

  1. blank
  2. empty
  3. null
  4. false
  5. The <body-content> subelement itself should be absent

10 . Which interface and method should be used to retrieve a servlet initialization parameter value?

  1. ServletConfig : getParameter(String name)
  2. ServletConfig : getInitParameter(String name)
  3. ServletContext: getInitParameter(String name))
  4. ServletConfig : getInitParameters(String name)
  5. ServletConfig : getInitParameterNames(String name)

11 . You need to put a com.enthu.User bean referred by ‘userBean’ variable in request scope with an ID of “user” from within a servlet. Which of the following statements accomplishes this task?

  1. request.put(“user”, userBean);
  2. request.add(userBean, “user”);
  3. request.putAttribute(“user”, userBean);
  4. request.setAttribute(“user”, userBean);
  5. request.setParameter(userBean, “user”);
  6. request.put(userBean, “user”);

12 . Consider the following code:

[code lang=”java”]
public class MyTagHandler extends TagSupport

{

public int doStartTag() throws JspException

{

try

{

//insert code here

}

catch(Exception e){ }

return super.doStartTag();

}

}
[/code]

Which of the following options, when inserted in the above code causes the value “hello” to be output?
Choose the one below:

  1. JspWriter out = pageContext.getOut();
    out.print(“hello”);
  2. JspWriter out = pageContext.getWriter();
    out.print(“hello”);
  3. JspWriter out = getPageContext().getWriter();
    out.print(“hello”);
  4. JspWriter out = new JspWriter(pageContext.getWriter());
    out.print(“hello”);
  5. JspWriter out = getPageContext().getOut();
    out.print(“hello”);

13 . Which of the following is a correct JSP declaration for a variable of class java.util.Date?

  1. <%! Date d = new Date() %>
  2. <%@ Date d = new Date() %>
  3. <%! Date d = new Date(); %>
  4. <%$ Date d = new Date() %>

14 . Which method can be invoked on a session object so that it is never invalidated by the servlet container automatically?

  1. setTimeOut(-1)
  2. setTimeOut(Integer.MAX_INT)
  3. setTimeOut(0)
  4. setMaxInactiveInterval(-1)
  5. setMaxInactiveInterval(Integer.MAX_INT)

15 . Which of the following elements are mandatory under the element of a deployment descriptor?

  1. <doctype>
  2. <app-name>
  3. <servlet>
  4. <doc-root>
  5. None of these

16 . Which of the following implicit variables should be used by a jsp page to access a page initialization parameter?

  1. pageContext
  2. application
  3. config
  4. context
  5. page

17 . You are given a tag library that has:

[code]
1. A tag named getMenu that takes an attribute ‘subject’ which can be a dynamic value.
2. A tag named getHeading that takes an attribute ‘report’.
[/code]

Which of the following are correct uses of this library?

Choose the one below:

  1. <myTL:getMenu subject=”Finance”/>
  2. <myTL:getMenu subject=”<myTL:getHeading report=1/>”/>
  3. <myTL:getMenu subject='<myTL:getHeading report=”1″/>’/>
  4. <% String subject=”HR”;%> <myTL:getMenu subject=”<%=subject%>”/>
  5. <myTL:getHeading report=”2″/>

18 . You are working with a tag library which is packaged in a jar file named htmlutil.jar.This jar file also contains a META-INF/htmlutil.tld file which has a uri element as follows:

[code]
<uri>http://www.xyzcorp.com/htmlLib</uri>
[/code]

What can you do to access this library from your JSP pages?

Choose the one below:

  1. You must define the <taglib> element in the web.xml to specify the mapping for <taglib-uri> to the location of this jar file
  2. There is no need for the <taglib> element in the web.xml, however, you need the taglib directive in the JSP pages
  3. You can directly access the tags of this library from the JSP pages without any taglib directive
  4. You do not need the taglib directive, but you do need to specify the <taglib> element in the web.xml
  5. None of these

19 . Which of the following are valid iteration mechanisms in jsp?

[code]
1.
<% int i = 0;
while(i<5)
{
"Hello World"
i++;
} %>

2.
<jsp:for loop=’5′>
"Hello World"
</jsp:for>

3.
<% int i = 0;
for(;i<5; i++)
{ %>
"Hello World";
<% i++;
}
%>

4.
<table>
<% Iterator it = aSet.iterator();
int i = 0;
while(it.hasNext())
{
out.println("<tr><td>"+(++i)+"</td>");
out.println("<td>"+it.next()+</td></tr>");
}
%>
</table>

5.
<jsp:scriptlet>
for(int i=0; i<5; i++)
{
</jsp:scriptlet>
<jsp:text>"Hello World!"</jsp:text>
<jsp:scriptlet>
}
</jsp:scriptlet>
[/code]

Choose the one below:

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5

20 . Your web application wants to make use of a role named ‘manager’, which is defined in the servlet container. Which of the following XML fragments must occur in the deployment descriptor of your web application?

[code]
1. <role name=’manager’ />

2. <role>
<role-name>manager</role-name>
</role>

3. <role>manager</role>

4. <security-role>
<role-name>manager</role-name>
</security-role>
[/code]

Choose the one below:

  1. 1
  2. 2
  3. 3
  4. 4

21 . Consider the class shown in exhibit. Which of the following statements are correct?

[code lang=”java”]
public class MyHSAListener implements HttpSessionAttributeListener
{
public void attributeAdded(HttpSessionBindingEvent e){ }
public void attributeRemoved(HttpSessionBindingEvent e){ }
}
[/code]

Choose the one below:

  1. public void attributeReplaced(…){ } must be added
  2. public void attributeChanged(…){ } must be added
  3. The parameter class should be HttpSessionEvent
  4. The parameter class should be HttpSessionAttributeEvent
  5. It will compile as it is

22 . Identify the implicit objects available to EL expressions?

  1. request
  2. sessionScope
  3. paramValues
  4. params
  5. cookie
  6. initParam

23 . Which of the following statements are correct regarding tag libraries?

  1. The tag library descriptor for a tag library must be kept in META-INF/taglib.tld, if the tag library is packaged in a jar file
  2. The tag library descriptor for a tag library may be kept in WEB-INF/taglib.tld, if the tag library is packaged in a jar file
  3. A JSP 2.0 compliant container is guaranteed to generate implicating mapping for JSTL tag libraries
  4. A JSP 2.0 compliant container will automatically generate an implicit tag library for a set of tag files
  5. The tag library descriptor for a tag library not packaged as a jar file may be kept anywhere in /tld directory of the web application’s document root

24 . Consider the following usage of a custom tag in a JSP page:

[code]
<jsp:useBean id="student" scope = "session" class="com.xyz.Student" />
<mytaglib:studentTag student=’student’ />
[/code]

Which of the following statements are correct?

Choose the one below:

  1. Application objects such as com.xyz.Student, cannot be passed as attributes to custom tags
  2. The Student object will be passed to the studentTag tag handler
  3. The Student object will NOT be passed because no variable named student is defined
  4. A Student object will not be created if it is not available it the session
  5. None of these

25 . Assuming that the Servlet Container has just called the destroy() method of a servlet instance, which of the following statements are correct?

  1. Any resources that this servlet might hold have been released
  2. The servlet container time out has exceeded for this servlet instance
  3. The init() method has been called on this instance
  4. None of the requests can EVER be serviced by this instance
  5. All threads created by this servlet are done

26 . For a tag to accept any valid jsp code as its body, what should be the value of for this tag’s taglib descriptor?

  1. JSP
  2. jsp
  3. any
  4. text
  5. The <body-content> subelement itself may be absent

27 . Which of the given options can be used in a servlet code that needs to access a binary file kept in WEB-INF/data.zip while servicing a request?
Assume that config refers to the ServletConfig object of the servlet and context refers to the ServletContext object of the servlet?

  1. InputStream is = config.getInputStream(“/WEB-INF/data.zip”);
  2. InputStream is = context.getInputStream(“data.zip”);
  3. InputStream is = context.getResourceAsStream(“/WEB-INF/data.zip”);
  4. InputStream is = context.getResourceAsStream(“WEB-INF/data.zip”);
  5. InputStream is = config.getResourceAsStream(“WEB-INF/data.zip”);

28 . Servlet Container calls the init method on a servlet instance?

  1. For each request to the servlet
  2. For each request to the servlet that causes a new session to be created
  3. For each request to the servlet that causes a new thread to be created
  4. Only once in the life time of the servlet instance
  5. If the request is from the user whose session has expired
  6. Initialy when the servlet instance is create and then at request time if the request is from the user whose session has expired

29 . Identify the implicit objects accessible to a jsp page that can store objects accessible across multiple requests?

  1. page
  2. request
  3. session
  4. application
  5. pageContext

30 . You are developing a jsp page named stockindices.jsp.This jsp page needs to use a HTML page named nasdaq.html in the middle of the page,which is updated every ten minutes by some other process.Which of the following lines,when added to stockindices.jsp,ensures that stockindices.jsp uses the latest nasdaq.html?

  1. <%@include page=’nasdaq.html’ %>
  2. <%@include file=’nasdaq.html’ %>
  3. <jsp:include page=’nasdaq.html’ />
  4. <jsp:include file=’nasdaq.html’ />
  5. <jsp:forward page=’nasdaq.html’ />

Answers

1 : 2 is correct.

2 : 2 & 4 is correct.

3 : 3 is correct.

4 : 3 is correct.

5 : 1,3 & 5 is correct.

6 : 3 & 4 is correct.

7 : 1 & 2 is correct.

8 : 2 is correct.

9 : 2 is correct.

10 : 2 is correct.

11 : 4 is correct.

12 : 1 is correct.

13 : 3 is correct.

14 : 4 is correct.

15 : 5 is correct.

16 : 3 is correct.

17 : 1,4 & 5 is correct.

18 : 2 is correct.

19 : 3,4 & 5 is correct.

20 : 4 is correct.

21 : 1 is correct.

22 : 2,3,5 & 6 is correct.

23 : 4 is correct.

24 : 5 is correct.

25 : 3 & 4 is correct.

26 : 5 is correct.

27 : 3 is correct.

28 : 4 is correct.

29 : 3 & 4 is correct.

30 : 3 is correct.

Filed Under: Certifications Tagged With: OCEJWCD, OCEJWCD 6

  • « Previous Page
  • 1
  • 2
  • 3
  • 4
  • …
  • 7
  • Next Page »

Follow Us

  • Facebook
  • Pinterest

As a participant in the Amazon Services LLC Associates Program, this site may earn from qualifying purchases. We may also earn commissions on purchases from other retail websites.

JavaBeat

FEATURED TUTORIALS

Answered: Using Java to Convert Int to String

What is new in Java 6.0 Collections API?

The Java 6.0 Compiler API

Copyright © by JavaBeat · All rights reserved