J2ee Amost Ans
J2ee Amost Ans
Q. No. 1
Question:
Which of the following is not a job of web container?
Answer Choices
A: Multi threading support
B: Applying thread safety
C: Providing Http Servlet request & response objects
D: Life cycle management of servlet & JSP
Q. No. 2
Question:
Your web application named bank uses WelcomeServlet. Where will you store
WelcomeServlet.class ?
Answer Choices
A: bank/WEB-INF/classes
B: bank/WEB-INF/lib/classes
C: root/WEB-INF/lib
D: bank/WebContent/build/classes
Q. No. 3
Question:
Name most suitable execution method in JDBC , for firing DML queries
Answer Choices
A: executeQuery
B:executeUpdate
C:execute
D:executeDynamicQuery
Q. No. 4
Question:
In the following code sample
Class.forName("oracle.jdbc.OracleDriver");
String dbURL = "jdbc:oracle:thin:@host1:1521:xe”;
Connection cn = DriverManager.getConnection(dbURL, "user", "pass");
How to create a Prepared Statement , to support scrollable & read only Result Set?
Answer Choices
A: cn.prepareStatement(sql, TYPE_SCROLL_INSENSITIVE,CONCUR_UPDATABLE);
B: cn.prepareStatement(sql, TYPE_FORWARD_ONLY,CONCUR_UPDATABLE);
C: cn.prepareStatement(sql, TYPE_SCROLL_INSENSITIVE,CONCUR_READ_ONLY);
D: cn.prepareStatement(sql, TYPE_SCROLLABLE,CONCUR_UPDATABLE);
Q. No. 5
Question:
In code below, cn – JDBC connection & add_me is already existing stored procedure on
the DB , which accepts 2 integers as IN parameters & result of addition is stored in 3 rd
OUT parameter.
What will be the result of the following code?
Format Type 1 (If answer choices are lengthy, one or more than one line)
Answer Choices
A:Compiler error
B:Prints addition of numbers
C:Run time error as OUT parameter is not registered
D:Run time error as IN parameters are not set correctly.
Q. No. 6
Question:
Choose appropriate transaction isolation level to prevent dirty reads & non-repeatable
reads.
Answer Choices
A: TRANSACTION_SERIALIZABLE
B: TRANSACTION_REPEATABLE_READ
C: TRANSACTION_READ_COMMITTED
D: TRANSACTION_READ_UNCOMMITTED
Q. No. 7
Question:
What method can be used to retrieve all the parameter values being sent as part of the
request by the client?
Answer Choices
A: Use the method 'HttpServletRequest.getParameterNames()' which will return an
enumeration of parameter names.
Q. No. 8
Question: Given the following code in a servlet ,
@WebServlet(urlPatterns = { "/s1" }, initParams = {
@WebInitParam(name = "test", value = "test123")})
public class AddCookie extends HttpServlet {
public void init() throws ServletException
{
ServletConfig config=getServletConfig();
System.out.println(“test=”+config.getInitParameter(“test”));
}
}
What will be output for above servlet, on server console?
Answer Choices
A: The Servlet will fail to load as the init param is not mentioned in the annotation.
B: Null Pointer Exception
C: test123
D: None of above
Q. No. 9
Question:
Consider Servlet1 & Servlet2 with code given below.
Servlet1 code
@WebServlet("/s1")
public class Servlet1 extends HttpServlet {
protected void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
try (PrintWriter pw = response.getWriter()) {
pw.print("from 1st page...");
response.sendRedirect(“s2”);
}
}
Servlet2 code
@WebServlet("/s2")
public class Servlet2 extends HttpServlet {
protected void doGet(HttpServletRequest request,HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
try (PrintWriter pw = response.getWriter()) {
pw.print("from 2nd page...");
}
}
What will be output on client browser & server console after giving URL of
http://host:8080/test/s1 (Assume that web server is running on localhost & servlets are
deployed in test1 web application)
Answer Choices
A: Displays ‘from 2nd page’ on client browser.
B: Displays ‘from 1st page’ on client browser.
C: Displays ‘from1st page’ on client browser & IllegalStateException on server console
Q. No. 10
Question:
Suppose you are developing online stock trading web application. Which is the most
appropriate scope to choose , to store information for available stocks , common for all
clients?
Answer Choices
A: Page B:Session
C: Request D:Application
Q. No. 11
Question:
Which of the following is inherently thread safe ?
Answer Choices
A:Session Scoped Attributes
B:Application scoped attributes
C:Servlet or JSP instance variables
D:Servlet or JSP method local variable
Q. No. 12
Question:
UserBean is created as java bean , with email property , suitable getter & setter.
Consider one.jsp
<jsp:useBean id=”user” class=”UserBean” scope=”request”/>
<jsp:setProperty name=”user” property=”email” value=”rama@gmail”/>
<a href=”two.jsp”>Next</a>
Consider two.jsp
Hello, ${user.email}
If Client clicks on Next link, what will be output on client browser?
Answer Choices
A: Hello
B: Hello, rama@gmail
Q. No. 13
Question:
What will be output on client browser , for following URL, provided web server is running
on localhost , port number 8080 & deployed application is test.
http://localhost:8080/test/check.jsp?event_id=1234
check.jsp contains
${param.event_id}
Answer Choices
A: 1234
B: Blank page
C:JSP translation time error
D:None of above
Q. No. 14
Question:
Your JSP page(test.jsp) 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?
Answer Choices
A: Add <%@page errorPage="error.jsp"%> in test.jsp & Add <%@page
isErrorPage="true"%> in error.jsp
Q. No. 16
Question:
In JSP pages , how to directly access context parameters , specific to a particular web
application?
Answer Choices
A:Using implicit object context
B: Using implicit object application
Below is important part JSP code(assume that rest of page directive attributes are
specified correctly)
Answer Choices
A: Translation time error.
B: Prints on client browser “Using Custom Tags” 1 time
Q. No. 18
Question:
What will be output on client browser for URL given as
http://www.abc.com:8080/bank/one.jsp
(Assume that web server is running on host www.abc.com & web application bank is
deployed)
one.jsp (only relevant part is specified)
<h3> Hello </h3>
<jsp:forward page=”two.jsp”/>
<h3> Hi </h3>
two.jsp (only relevant part is specified)
<h3>Hello again></h3>
Answer Choices
A: Hello Hello again Hi in proper format.
B:IllegalStateException
C:Hello Hi in proper format.
D:Hello again in proper format.
Q. No. 19
Question: What will be output for URL given as
http://www.abc.com:8080/bank/one.jsp
(Assume that web server is running on host www.abc.com & web application bank is
deployed and client has disabled cookies)
Code in one.jsp
<jsp:useBean id="dt" class="java.util.Date"/>
<c:set var="test" value="${dt}" scope="session"/>
<c:redirect url="two.jsp" />
Code in two.jsp
<h3> From 2nd page : <c:out value="${dt}"/> </h3>
Format Type 1 (If answer choices are lengthy, one or more than one line)
Answer Choices
A: From 2nd page : Current date is printed
B: From 2nd page
C: Blank page
Q. No. 20
Question:
Which is the best approach to ensure thread safety for context scoped attributes ?
Answer Choices
A:Access context scoped attributes from within the synchronized block , locked on
application(ServletContext)
D:Nothing is required since context scoped attributes are inherently thread safe.
Q. No. 21
Question:In hibernate application, what is the effect of invoking evict method on
hibernate session?
Answer Choices
A:Unpredictable results
B: Session level cache is cleared.
C: Removes specified POJO from session cache.
D: POJO becomes persistent
Q. No. 22
Question:
Specify mandatory annotations for creating Hibernate based POJO or Entity class.
Answer Choices
A: @Entity , @Table , @Id , @Column
B: @Serializable, @Table
C: @Entity , @Id
D: @Entity , @Id , @Table
Q. No. 23
Which of the following statements is false in hibernate based web application?
Question:
Answer Choices
A: Its mandatory to create Context listener , to initialize hibernate framework.
B: Hibernate does not support reverse engineer tools.
C : Hibernate POJOs may not be Serializable.
D : Hibernate POJO ‘s ID property may not be Serializable.
Q. No. 24
Question:Which of the following is true about load & get methods of hibernate session?
Answer Choices
A: Lazy Initialization exception is not raised in get method.
B: load method returns null if POJO is not found.
C: load uses eager fetching policy always.
D: get uses lazy fetching policy always.
Q. No. 25
Question:
Which of the following is NOT a role of the Hibernate session interface?
Answer Choices
A: Holds a mandatory (first-level) cache of persistent objects, used when navigating the
object graph or looking up objects by identifier.
Q. No. 26
Question:
What will be result of following OGNL expression ?
<s:property value=”#application.customer.id/>
Answer Choices
A: Customer id will be evaluated from value stack
B: Customer id will be evaluated from context scoped attribute
C: Customer id will be evaluated from request parameter.
D: Invalid syntax
Q. No. 27
Question:
Specify thread safety regarding Struts 2 interceptors & actions.
Format Type 1 (If answer choices are lengthy, one or more than one line)
Answer Choices
A:Both are inherently thread safe.
B: Both are inherently thread unsafe.
C: Inherently interceptors are thread unsafe & actions are thread safe.
D: Inherently interceptors are thread safe & actions are thread unsafe.
Q. No. 28
Question:
What will happen if Struts 2 validator framework detects validation error?
Answer Choices
A: If result , name=input , is not specified, exception will be raised.
B: Business logic execution does not take place.
C: If result , name=input , is specified, workflow is diverted to specified input page.
D: All of above options are valid.
Q. No. 29
Question:
What are advantages of Struts 2 over Struts 1?
Answer Choices
A: Introduction of Interceptors
B: Addition of OGNL
C: Inherent thread safety of struts2 actions
D: All of above
Q. No. 30
Question:
What is the need of Model Driven Interceptor in Struts2?
Answer Choices
A: For supporting client side validation framework
B: For automatic conversion of request parameters to Model data.
C: For clean separation between domain object & business logic
D: All of above.
Q. No. 31
Question:
Which of the following is not a role of EJB container?
Answer Choices
A: Instance Pooling of Stateless Session beans
B: Managing Entity life cycle
C: Managing servlet life cycle
D: Providing cache management for Stateful session beans
Q. No. 32
Question:
What is NOT true regarding Stateless Session Beans of EJB 3.x specification?
Answer Choices
A: Stateless Session Beans being light weight , are highest performant.
B: Stateless Session Beans follow pool based life cycle
C: Stateless Session Beans do not use activation & passivation call backs.
D: When remote client invokes any method annotated with @Destroy on Stateless
Session bean , EJB container immediately marks it for garbage collection.
Q. No. 33
Question:
If cache type for Stateful Session bean is chosen as NRU(Not recently used),
When will EJB container begin passivation?
Answer Choices
A: If any of Stateful session bean in active cache exceed idle timeout.
B: If number of client requests exceed max cache size.
C: A & B
D: None of above
Q. No. 34
Question:
For online banking based application, which type is best fit to represent a bank
customer, whose details are stored in database?
Answer Choices
A: Stateless Session Bean
B: Stateful Session Bean
C: Message Driven Bean
D: JPA based entity.
Q. No. 35
Question:
What is mandatory requirement for implementing Stateful session bean?
Answer Choices
A: Stateful session bean class must implement Serializable interface.
B: Properties of Stateful bean , representing client’s conversational state must be non
transient & Serializable.
C: Must specify primary key as unique identifier & annotate it correctly.
D: A & B both.
Q. No. 36
Question:
What is NOT true regarding Message Driven Bean’s life cycle & its configuration?
Answer Choices
A: It follows pool based life cycle.
B: Implements MessageListener interface to service incoming asynchronous
messages.
C: @PostConstruct & @PreDestroy call backs are never called.
D: Must configure destination & its type either via XML or annotations.
Q. No. 37
Question:
In Spring AOP, which type of advice can prevent execution of business logic?
Answer Choices
A: Before
B: After
C: After Throwing
D: Around
Q. No. 38
Question:
Choose suitable class level annotation for web application request handler layer , while
integrating spring with hibernate.
Answer Choices
A: @Singleton
B: @Controller
C: @Repository
D: @Service
Q. No. 39
Question:
What is the significance of BindingResult in Spring web MVC architecture?
Answer Choices
A: It stores client’s conversational state.
B: Stores result of conversion & validations of the client’s conversational state.
C: Stores session scoped attributes.
D: All of above.
Q. No. 40
Question:
Suggest suitable transaction propagation attribute in Spring framework ,that does not
support a current transaction; throw an exception if a current transaction exists.
Answer Choices
A: MANDATORY
B: REQUIRED
C: SUPPORTS
D: NEVER
Q. No. 41
Question:
In JSF life-cycle , which phase is used for storing incoming form parameter values in
server-side UI component objects?
Answer Choices
A: Apply Request Values
B: Restore View
C:Update Model Values
D:Process Validation
Q. No. 42
Question:
In JSF , which is the annotation used for dependency injection ?
Answer Choices
A: ManagedBean
B:ManagedProperty
C:ViewScoped
D:RequestScoped