0% found this document useful (0 votes)
20 views

JAVA

The document discusses Spring Core and Spring Data JPA. Some key points: - Spring Core provides dependency injection and inversion of control to simplify object creation and management. It uses plain old Java objects (POJOs) and has a layered architecture. - Spring Data JPA is a Spring module that simplifies database access using Java Persistence API (JPA). It provides annotations like @Entity, @Id, and @JoinTable to map entities to tables and define relationships between entities. - Spring Core supports constructor injection, setter injection, and method injection for dependency injection. It uses singleton and prototype scopes to manage bean lifecycles. The default scope is singleton. - Features of Spring

Uploaded by

lyltn.21it
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views

JAVA

The document discusses Spring Core and Spring Data JPA. Some key points: - Spring Core provides dependency injection and inversion of control to simplify object creation and management. It uses plain old Java objects (POJOs) and has a layered architecture. - Spring Data JPA is a Spring module that simplifies database access using Java Persistence API (JPA). It provides annotations like @Entity, @Id, and @JoinTable to map entities to tables and define relationships between entities. - Spring Core supports constructor injection, setter injection, and method injection for dependency injection. It uses singleton and prototype scopes to manage bean lifecycles. The default scope is singleton. - Features of Spring

Uploaded by

lyltn.21it
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 32

SPRING CORE

SPRING CORE

1. What is not an advantages of Spring framework?


A. It is an open-source framework
B. It does not support conventional POJO programming rather it
has own mechanism
C. It has layered architecture
D. Dependency Injection and Inversion of Control Simplifies
JDBC

 B. It does not support conventional POJO programming


rather it has own mechanism

2. Identify the true option about Dependency Injection


A. It helps in tight coupling the application objects.
B. It helps to store objects in heap.
C. It is a technique to get dependencies of any spring project.

D. It helps in decoupling application objects from each other.


D
3. Which type of dependency injection Spring framework does not
support?
A. Construction Injection
B. Setter Injection
C. Interface Injection
C
4. Which is not a correct implementation of ApplicationContext?
A. ApplicationContext context = new
ClassPathXmlApplicationContext("bean.xml");
B. ApplicationContext context = new
FileSystemXmlApplicationContext("bean.xml");
C. ApplicationContext context = new
WebApplicationContext("bean.xml");
C
5. Can IoC container instantiate beans using private constructors?
A. Yes
B. No
A
6. Which of the following is not the feature of IoC?
A. Object creation
B. Dependency Injection
C. Life Cycle Management
D. Transaction Management
D
7. Which of the following is true regarding the @Autowired
annotation?
a. It is possible to provide all beans of a particular type from the
ApplicationContext by adding the annotation to a field or
method that expects an array of that type.
b. Typed Maps can be autowired as long as the expected key
type is String.
c. By default, the autowiring fails whenever zero
candidate beans are available.
d. All of the above.
d
8. Which statements are true about IoC (Inversion of Control) ?
(multiple choice)
a. Decoupling of the execution of a certain task from
implementation.
b. Each module can focus on what it is designed for.
c. Replacing modules should not affect to other modules.
d. Modules should observe about what other systems do .
 A , B, C
9. Which of the following is not a component of the Spring
framework?
a. AOP
b. O/R Integration
c. Spring MVC
d. HTML/JSP
D
10. Which is true about Bean scopes in Spring Framework?
a. Prototype - a single bean definition to any number of object
instances.
b. Singleton - a single bean definition to a single object instance
per Spring IoC container.
c. Session - a single bean definition to the lifecycle of a HTTP
Session. Only valid in the context of a web-aware Spring
ApplicationContext."
d. All of these
D
11. "What is bean autowiring?"
a. Autowiring helps in wiring a list of values, allowing
duplicates.
b. Autowiring lets Spring resolve collaborators otherbeans for
your bean by inspecting the contents of the BeanFactory
without using <constructor-arg> and <property> elements.

c. Autowiring injects one bean into another bean.


d. Autowiring injects values in spring factory beans.
B
12. What is the default scope of a bean in Spring IoC?
a. Abstract
b. Singleton
c. Final
B
13. Which are the different modes of autowiring?
a. byName , byType, destructor and autodetect
b. byName , byMethod, constructor and autodetect
c. byName , byType, constructor and autocorrect
d. byName , byType, constructor and autodetect
D
14. What are Bean scopes in Spring Framework ? .
a. Request, Session, Page, Application
b. Singleton, Prototype, Request, Session and Global Session.

c. Singleton, Prototype, Session and Global Session.


d. Singleton and Prototype
B
15. Which scope creates a new bean instance each time when
requested?
a. Singleton
b. Prototype
c. Session
B
16. Which configuration can be used for Dependency Injection?
a. XML Configuration
b. Annotation Configuration
c. Java Based Configuration
d. All of the mentioned
=>D
17. Which of the following is not a valid difference between
@Inject and @Autowired annotations?
a. @Inject annotation is part of Java EE 7’s Context and
Dependency Injection framework while @Autowired is the
Spring Frameworks own implementation.
b. There is no difference and both can be used interchangeably.

c. @Autowired is a legacy annotation whereas @Inject is its


latest version.
C
18. What is request scope?
a. This scopes a bean definition to an HTTP request.
b. This scopes the bean definition to Spring IoC container.
c. This scopes the bean definition to HTTP Session.
d. This scopes the bean definition HTTP Application/ Global
session.
A
19. By default a bean is eagerly loaded.
a. FALSE
b. TRUE
B
20. What is byType mode of autowiring?
a. Default setting which meas no autowiring and you should use
explicit bean reference for wiring.
b. Autowiring by property name. Spring tries to match and wire
its properties with the beans defined by the same names in
the configuration file.
c. Spring first tries to wire using autowire by constructor, if it
does not work, Spring tries to autowire by byType.
d. Autowiring by property type. Spring tries to match and wire a
property if its type matches with exactly one of the beans
name in configuration file.
D
21. "What is spring?"
a. Spring is a light weight open source development framework
for enterprise Java.
b. Spring is a heavy weight open source development
framework for enterprise Java.
c. Spring is a proprietary framework.
d. Spring is a development framework for .Net applications.
A
22. What is Dependency Injection?
a. It is a design pattern which implements Inversion of Control
for software applications.
b. It is one of the spring module.
c. It is a technique to get dependencies of any project.
d. It is used to promote tight coupling in code.
A
23. How do you turn on annotation wiring?
a. Add <annotation-context:config /> to bean configuration

b. Add <annotation-config /> to bean configuration.


c. Add <annotation-context-config /> to bean configuration.

d. Add <context:annotation-config/> to bean configuration.


D
24. How can you inject Java Collection in Spring?
a. Using list, set, map or props tag.
b. Using lit, set, map or collection tag.
c. Using list, set, props or collection tag.
d. Using list, collection, map or props tag.
A
25. What is no mode of autowiring?
a. Default setting which means no autowiring and you should
use explicit bean reference for wiring.
b. Autowiring by property name.
c. Spring first tries to wire using autowire by constructor, if it
does not work, Spring tries to autowire by byType.
d. Similar to byType, but type applies to constructor argument
A
26. By default a bean is lazily loaded.
a. TRUE
b. FALSE
B
27. Which class acts as IoC Container?
a. ServletContext
b. DispatcherServlet
c. ApplicationContext
d. None of the above
C
28. How to use ref keyword in beans?
a. Using setter method only.
b. Using setter method only.
c. Using setter method and constructor argument both.
d. None of the above.
C
29. Which of the following stands true for spring beans?
a. Spring beans are managed by the Spring IoC container.
b. Spring beans are instantiated, assembled, and otherwise
managed by a Spring IoC container.
c. Spring beans are simple POJOs.
d. All of the above.
D
30. How bean life cycle can be controlled?
a. Using init() only
b. Using InitializingBean class only
c. Using DisposableBean class only Using
d. All of above
D
31. Can we inject value and ref both together in a bean?
a. TRUE
b. FALSE
A
32. Which is the way to provide configuration metadata to
spring?
a. XML Based configuration file.
b. Annotation based configuration.
c. Java based configuration.
d. All of the above
D
33. What is global-session scope?
a. This scopes a bean definition to an HTTP Application/
Global session.
b. This scopes the bean definition to Spring IoC container.
c. This scopes the bean definition to HTTP request.
d. This scopes the bean definition to HTTP Session
A
34. Which is the correct implementation class of BeanFactory?
a. XmlBeanFactory
b. ClassPathBeanFactory
c. FileSystemBeanFactory
d. AdvancedBeanFactory
=>A
35. What is session scope?
a. This scopes a bean definition to an HTTP session.
b. This scopes the bean definition to Spring IoC container.
c. This scopes the bean definition to HTTP request.
d. This scopes the bean definition to HTTP Application/ Global
session.
A
36. "How to get object of a service in Spring framework?"
a. Using new keyword
b. Using dependency injection
=> B
37. "Bean’s naming convention:
- starts with a lowercase letter,
- and are camel-cased from then on?"
a. TRUE
b. FALSE
=> A

SPRING DATA JPA

1. Which of the following annotation is used for Is-A mapping?


A. @Inheritance
B. @IsAMapping
C. @InheritanceMapping
A
2. Which annotation is used to link two tables through a relation table?
A. @RelatonTable
B. @JoinTable
C. @LinkTable
B
3. Which of the following is not a mandatory annotation for an entity class?
A. @Entity
B. @Table
C. @Id
B
4. Which of the following annotation is applied on the unique Id of an entity to get its
value generated?
A. @Generator
B. @GeneratedValue
C. @Unique
D. @AutoIncrement
B
5. Which annotation is used to create PK-FK relation beetween two tables?
A. @JoinColumn
B. @ForeignKey
C. @JoinedKey
D. @PrimaryKey
A
6. Which attribute of @OneToMany is used to mark an entity as owned?
A. cascade
B. mappedBy
C. propertyRef
D. eager
B
7. Which of the following Is-A mapping, requires discriminator column?
A. Single Table Mapping
B. Joined Table Mapping
C. Table Per Class Mapping
D. Double Table Mapping
A
8. What is ACID in transactional management?
A. Accurate, Controlled, Isolation, Durability
B. Atomicity, Consistency, Independent, Done
C. Atomicity, Consistency, Isolation, Durability
D. Accurate, Controlled, Independent, Done
C
9. Which of the following database is not supported using JdbcTemplate?
A. MySql
B. PostgresSql
C. NoSql
D. Oracle
C
10. Which of the following class can be used to call Stored Procedures in Spring JDBC?
A. SPHelper
B. JdbcTemplateCall
C. JdbcTemplate
D. SimpleJdbcCall
D
11. Which ORM Spring supports (Multiple choices)?
A. Hibernate
B. iBatis
C. JPA
A,B,C
12. Which of the following class can be used to execute SQL queries in Spring?
A. JDBCHelper
B. JdbcTemplate
C. DBHelper
D. DBTemplate
B
13. What are the ways to access Hibernate by using Spring?
A. Inversion of Control with a Hibernate Template and Callback
B. Extending HibernateDAOSupport and Applying an AOP Interceptor node.
C. Both of above.
D. None of above.
C
14. Which class is used to map a database row to a java object in spring?
A. ResultSet
B. RowMapper
C.RowSetMapper
D.ResultSetMapper
B
15. What are the types of the transaction management Spring supports?
A. Programmatic transaction management
B. Declarative transaction management
C. Both of above.
D. None of above.
C
16. Spring supports the following ORM’s (apply all):
A. Hibernate
B. iBatis
C. JPA (Java Persistence API)
D.Hibernate and JPA
A,B,C
17. What AOP stands for?
A. Aspect Oriented Programming
B. Any Object Programming
C. Asset Oriented Programming
D. Asset Oriented Protocol
A
18. Which are the modules of Data Access/ integration layer?
A. JDBC, ORM, OXM, JMS, Transactions
B. JDBC, ORM, OXM, JMS
C. JDBC, ORM, Web, Beans
D. JDBC, ORM, OXM, JMS
A
19. What is the JPA equivalent of hibernate.cfg.xml file?
A. configuration.xml
B. persistence.xml
C. jpa.configuration.xml

B
20. Which method of CrudRepository to returns the entity identified by the given id?
A. T findById(ID primaryKey);
B. T getById(ID primaryKey);
C. T findOne(ID primaryKey);
D. T getOne(ID primaryKey);
C

SPRING WEB MVC

1. What is a DispatcherServlet?
A. Used for Dependency Injection.
B. Handles all the HTTP requests and responses.
C. Used for Spring AOP.
D. Used for transaction management.
B
2. Controller in Spring is .. .
A. a abstract class
B. concrete class
C. final class
D. an interface
D
3. --- is required to load the beans configured in applicationContext.xml file?
A. ContextLoader
B. ContextLoaderListener
C. ApplicationContextLoader
B
4. Where do you cannot declare Spring MVC controller? (multiple choise)
A. In a Spring application context XML configuration file
B. Into the web.xml file of the web application
C. Into the java code by using annotations
D. Into the JSP pages
B,D

5. Which of the following layers the @Controller annotation is used in?


A. Business layer.
B. Presentation layer.
C. Service layer.
D. Persistence layer.
B
6. Design pattern implemented by Dispatcher Servlet.
A. jsp tiles
B. front controller
C. none of the mentioned
C
7. Class used to give a class behavior of a Dispatcher Servlet.
A. AbstractController
B. Controller
C. Abstract Class
D. AbstractAction
A
8. Annotation for Controller class?
A. @Before
B. @Controller
C. @After
D. @Servlet
B
9. What is @Controller annotation?
A. The @Controller annotation indicates that a particular class serves the role of a
controller.
B. The @Controller annotation indicates how to control the transaction
management.
C. The @Controller annotation indicates how to control the dependency injection.

D. The @Controller annotation indicates how to control the aspect programming.


A
10. What does @Required annotation mean?
A. This annotation indicates that bean property must be populated by the user.

B. This annotation indicates that bean property is required while saving the bean
data to database.
C. This annotation simply indicates that the affected bean property must be
populated at configuration time, through an explicit property value in a bean
definition or through autowiring.
D. This annotation indicates that bean property is required while serializing the
bean.
C
11. Where do you define DispatcherServlet?
A. In Beans configuration file
B. web.xml file
C. META-INF/dispatcher.xml
D. WEB-INF/dispatcher.xml
B
12. Which are the modules of Web layer?
A. WebSocket, Servlet, Web, Portlet
B. WebSocket, Servlet, Web-MVC, Web
C. HTML, JSP, WEB, Portlet
D. HTML, Servlet, WEB, Portlet
A
13. What is Spring MVC framework?
A. Spring MVC framework is Model-Value-Class architecture and used to bind
model data with values.
B. The Spring web MVC framework provides model-view-controller architecture
and ready components that can be used to develop flexible and loosely coupled
web applications.
C. Spring MVC framework is used for Transaction management for Web
Applications.
D. Spring MVC framework is used for AOP for Web Applications.
B
14. What is RequestHandledEvent:event?
A. This event is published when the Servlet Context is either initialized or
refreshed.
B. This event is published when the HTTP Request is received.
C. This event is published when the HTTP session is initialized or refreshed.

D. This event is published when the HTTP Request is serviced.


C
15. @RequestMapping annotation is used to map a HTTP request method (GET or
POST) to a specific class or method in the controller which will handle the
respective request?
A. FALSE
B. TRUE
B
16. What annotation is used to map value to the method argument in
http://localhost/factorial/{value}?
A. @Map
B. @Param
C. @RequestParam
D. @PathVariable
D
17. In Spring Web App, which of the following acts as a Front Controller?
A. @RestController
B. DispatcherServlet
C. Models
D. Views
B
18. What annotation is used to map a method for PUT request?
A. @PutMapping
B. @PostMapping
C. @Put
D. @Post
A
19. Callback methods provided by HandlerInterceptor to implement.
A. preHandle()
B. postHandle()
C. afterCompletion()
D. All of the mentioned
D
20. Handler method annotation.
A. @Before
B. @Controller
C. @After
D. @RequestMapping
D
21. Annotation which represents cookie values of requests.
A. HttpServletRequest or HttpServleResponse
B. @RequestParam
C. @Cookie
D. None of the mentioned
D
22. To add attributes to the model.
A. Map
B. ModelMap
C. All of the mentioned
D. None of the mentioned
C
23. To notify its completion of session processing.
A. Errors
B. BindingResult
C. SessionStatus
D. one of the mentioned
C
24. Controller Class renders the objects passed by the controller’s handler method.
A. TRUE
B. FALSE
A
25. Parameter used to specify a configuration file.
A. contextConfigLocation
B. contextConfigure
C. contextLocation
D. None of these
A
26. Bean classes pre-registered in the web application context by default.
A. DefaultAnnotationHandlerMapping
B. AnnotationMethodHandlerAdapter
C. All of the mentioned
D. None of the mentioned
C
27. Method arguments that can be used in handler methods using the
@RequestMapping annotation.
A. HttpServletRequest or HttpServleResponse
B. @RequestParam
C. @ModelAttribute
D. All of the mentioned
D
28. Which is not a proper way to access Hibernate using Spring?
A. Extending HibernateDaoSupport and applying an AOP Interceptor
B. Inversion of Control with a HibernateTemplate and Callback.
C. All of the mentioned
D. None of the mentioned
B
29. Which component is used to map a request to a method of a controller?
A. RequestMapping
B. RequestMapper
C. URLMapper
D. RequestResolver
A
30. "What could not return a Spring MVC controller?
A. An absolute path to the view
B. A logical view name
C. A new JstlView
D. void
A
31. ___object is used by a request processing method to check validation failure?
A. ValidationErrors
B. BindingResult
C. ValidationBinding
B
32. Which annotation is required to receive a model object initialized by the request
parameters, in a request processing method?
A. @RequestParam
B. @ModelAttribute
C. @ModelObject
B
33. By default, @RequestMapping gets all the POST Requests.
A. TRUE
B. FALSE
B
34. The @RequestMapping annotation can be applied to the class level only.
A. TRUE
B. FALSE
B
35. To access the binding and validation result for the command object.
A. Errors
B. BindingResult
C. All of the mentioned
D. None of the mentioned
C

JAVA WEB

1. The include() method of RequestDispatcher


A. Sends a request to another resource like servlet, jsp or html
b. Includes resource of file like servlet, jsp or html
c. Appends the request and response objects to the current servlet
=>A
2. What programming language(s) or scripting language(s) does Java Server Pages
(JSP) support?
a. VBScript only
b. Jscript only
c. Java only
d. VBScript, Jscript and Java
=>c
3. 3. A JSP is transformed into a(n):
a. Java Applet
b. Java Servlet
c. Java Script
=>b
4. 4. What is the key difference between using a <jsp:forward> and
HttpServletResponse.sendRedirect()?
A forward executes on the server while sendRedirect() executes on the client

B forward executes on the client while sendRedirect() executes on the server

C The two methods perform identically


D None of these
=>a
5. 5. Which of the following can not be used as the scope when using a JavaBean
with JSP ?
A application
B response
C request
D session
=>b
6. 6. What is wrong with the following code ?
<% if( strPassword.equals("boss")){
<jsp:forward page="Welcome.jsp" flush="true"/>}
else{}%>

A Unmatched bracket in for statement


B Flush attribute must be false
C Keyword 'file' should be used instead of 'page' in the action
D Actions cannot be used within scriptlet blocks
=>d
7. 7. Choose the statement that best describes the relationship between JSP and
servlets:
=>D
A. Servlets are built on JSP semantics and all servlets are compiled to JSP pages
for runtime usage
B. JSP and servlets are unrelated technologies
C. Servlets and JSP are competing technologies for handling web requests.
Servlets are being superseded by JSP, which is preferred. The two technologies are
not useful in combination
D. JSPs are built on servlet semantics and all JSPs are compiled to servlets for
runtime usage
8. 8. Which of the following is true about Execution phase in JSP life cycle?
A. Whenever a browser requests a JSP and the page has been loaded and
initialized, the JSP engine invokes the _jspService() method in the JSP.
B. The _jspService() method of a JSP is invoked once per request and is
responsible for generating the response for that request.
C The _jspService() method of a JSP generates responses to all seven of the HTTP
methods ie. GET, POST, DELETE etc.
D All of the above.
D
9. 9. What is the use of <c:if> tag?
=B
A. It is used to check if jsp tag library is enabled or not.
B. It evaluates an expression and displays its body content only if the expression
evaluates to true.
C. No tags in JSP
10. 10. What is the use of <c:catch> tag?
=A
A. To catch any Throwable that occurs in its body and optionally exposes it.
B. To catch the runtime error and redirect to error page.
C. Both of the above.
D. None of the above.
11. 11. Which of the following is a server side technology?
=B
A. HTML
B. JSP
C. JavaScript
D. CSS
12. 12. Which of the following is true about <jsp:setProperty> action?
=C
A. The setProperty action sets the properties of a Bean.
B. The Bean must have been previously defined before using setProperty action

C. Both of the above.


D. None of the above.
13. 13. What is javax.servlet.http.HttpServlet?
=B
A. interface
B. abstract class
C. concreate class

14. 14. pageContext is instance of which class?


=C
A. javax.servlet.ServletContext
B. javax.servlet.ServletConfig
C. javax.servlet.jsp.PageContext
D. javax.servlet.Application
15. 15. Which is the methods of generated Servlet?
=D
A. jspInit()
B _jspService()
C jspDestroy()
D All of the above
16. 16. The method forward(request, response) will__?
=A
A return back to the same method from where the forward was invoked
B not return back to the same method from where the forward was invoked and
the web pages navigation continues
C Both A and B are correct
D None of the above
17. 17. The Web server that executes the servlet creates a_________ object and passes
this to the servlet's service method (which, in turn, passes it to doGet or doPost).

=D
A. HttpServletResponce
B. HttpRequest
C. HttpResponce
D. HttpServletRequest

18. The client can access the servlet only if the servlet is installed on a ________ that
can respond to servlet requests.
=B
A. client
B.server
C.internet
D.in your network
19. All servlets must implement the Servlet interface of package:
=B
A. java.servlet
B. javax.servlet
C. java.http.servlet
D. java.io
20. Which of the following code can be used to redirect user to different url?
=B
A. request.sendRedirect(location)
B. response.sendRedirect(location)
C. header.sendRedirect(location)
D. session.sendRedirect(location)
21. Which of the following code retrieves the context of the request?
=B
A. new ClassContextPath()
B. request.getContextPath()
C. response.getContextPath()
22. A get request gets information from a client. A post request posts data to a client.
=B
A. TRUE
B. FALSE
C. Not always
D. None of these
23. What is the difference between doing an include or a forward with a
RequestDispatcher?
=D
A. The two methods provide the same functionality, but with different levels of
persistence
B. The forward method is deprecated as of JSP 1.1 and the include method should
be used in order to substitute portions of a dynamic display at runtime
C. The include method transfers control to a dynamic resource, while the forward
method allows for dynamic substitution of another JPS pages output, returning
control to the calling resource
D. The forward method transfers control to the designated resource, while the
include method invokes the designated resource, substitutes its output dynamically
in the display, and returns control to the calling page
24. Which of the following values are invalid RequestDispatcher types:
=D
A. Request
B. Forward
C. Error
D. Jsp
25. Considering the following Servlet code, choose the statements which are true:

package com.nullhaus;
import javax.servlet.annotation.*;
import javax.servlet.http.*;

@WebServlet(name=""NullServlet"")
public class NullServlet extends HttpServlet {

}
A. This is a valid usage of @WebServlet annotation
B. This is an invalid usage of @WebServlet annotation
C. This code compiles
D. This code doesn’t compile
B,C
26. Which of the following request attributes that an error-handling servlet can access
to analyse the nature of error/exception?
A. javax.servlet.error.status_code
B. javax.servlet.error.exception_type
C. javax.servlet.error.message
D. All of the above
D
27. Which of the following is true about request scope?
A. Object created with request scope are accessible only from the page in which they
are created.
B. Object created with request scope are accessible only from the page in which they
are created.
C. Object created with request scope are accessible only from the pages which are
processing the same request.
D. Object created with request scope are accessible only from the pages which reside
in same application.
C
28. Considering the following HTML form code snippet and the servlet code, what
will be the result of servlet invocation after the form has been submitted?

<!-- form.html -->


<form action=""myServlet?var=q1&var=q2"" method=""POST"">
<input name=""var"" type=""hidden"" value=""q3"" />
<input type=""submit"" />
</form>

<!-- NullServlet.java -->


package com.nullhaus;
import javax.servlet.annotation.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
@WebServlet(""/myServlet"")
public class NullServlet extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse resp) {
String[] param = req.getParameterValues(""var"");
resp.getWriter().println(Arrays.toString(param));
}
}
A. [q1, q2, q3]
B. The above code doesn’t compile
C. [q1, q2]
D. [q3]
A
29. Which statements are true about the web applications created with
Servlets 3.0? (Choose two)
A. The web.xml file is required
B. The web.xml file is not required
C. The WEB-INF/ directory is required
D. The WEB-INF/ directory is not required
B,D
30. To send binary output to response, which method of HttpServletResponse is used
to get the Writer/ Stream object ?
A. getStream
B. getWriter
C. getBinaryOutputStream
D. getOutputStream
D
31. Which of the following code can be used to write a cookie?
A. request.addCookie(cookie)
B. response.addCookie(cookie)
C. Header.addCookie(cookie)
D. None of the above.
B
32. Which of the following code can be used to send an error response to the client
using the specified status code and clearing the buffer.
A. request.sendError(statusCode)
B. response.sendError(statusCode)
C. header.sendError(statusCode)
D. None of the above.
B

33. Which of the following code can be used to set the content type for the body of
the response?
A. request.setContentType(type)
B. response.setContentType(type)
C. header.setContentType(type)
D. None of the above.
B
34. Which of the following code is used to delete an attribute from a HTTP Session
object in servlets?
A. session.removeAttribute(name)
B. session.alterAttribute(name)
C. session.updateAttribute(name)
D. None of the above.
A
35. Which of the following code is used to get session id of a HTTP Session object
in servlets?
A. session.getSessionId()
B. session.getId()
C. session.getActiveId()
D. None of the above.
B
36. Which of the following code is used to update an attribute in a HTTP Session
object in servlets?
A. session.setAttribute(name, value)
B. session.alterAttribute(name, value)
C. session.updateAttribute(name, value)
D. None of the above.
A
37. Which of the following code is used to get session in servlet?
A. request.getSession()
B. response.getSession()
C. new Session()
D. None of the above
A
38. Which of the following code is used to get an attribute in a HTTP Session object in
servlets?
A. session.getAttribute(name)
B. session.alterAttribute(name)
C. session.updateAttribute(name)
D. None of the above
A
39. Which of the following is not a implicit object?
A. request
B. response
C. cookie
D. session
C
40. The getSession() method with 'true' as its parameter [ getSession(true) ] it will
return the appropriate session object when__
A. The session is completed
B. The session object is passed to another method
C. The session does not exists
D. The session is existing
D
41. Which of the following code is used to set the session timeout in servlets?
A. session.setMaxInactiveInterval(interval)
B. response.setMaxInactiveInterval(interval)
C. request.setMaxInactiveInterval(interval)
D. session.setTimeOut(interval)
A
42. Which of the following code is used to add an attribute in a HTTP Session object
in servlets?
a. session.addAttribute(name,value)
b. session.setAttribute(name,value)
c. session.createAttribute(name,value)
d. None of the above.
B
43. What are the true sentences about Session-Id?
a. Session-IDs are usually stored in the cookies, URLs and hidden fields of Web
pages
b. A session-ID is an unique identification
c. It is transmitted between the client and the server
d. All of these
D
44. What is the purpose of session management?
a. To manage the user's login and logout activities
b. To store information on the client-side between HTTP requests
c. To store information on the server-side between HTTP requests
d. To tell the web container to keep the HTTP connection alive so it can make
subsequent requests without thedelay of making the TCP connection
C
45. Which of the following are the session tracking techniques?
a. URL rewriting, using session object, using response object, using hidden field
b. URL rewriting, using session object, using cookies, using hidden fields
c. URL rewriting, using servlet object, using response object, using cookies
d. URL rewriting, using request object, using response object, using session object
B
46. Consider the following Deployment Descriptor code snippet:
...
<filter>
<filter-name>NullFilter 1</filter-name>
<filter-class>com.nullhaus.NullFilter</filter-class>
</filter>
...

and the following Filter code:

package com.nullhaus;
import javax.servlet.annotation.*;
import javax.servlet.*;
@WebFilter(urlPatterns = {""/*""}, filterName=""NullFilter 1"")
public class NullFilter implements Filter {
// necessary methods goes here
}

Knowing that above DD snippet is the only filter-related part, how many filter
instances will be created by the Servlet container?
a. 0
b. 2
c. 1
d. Deployment Descriptor is invalid and the runtime exception will be thrown
C
47. Where filters are defined?
a. Filters are defined in the deployment descriptor file web.xml.
b. Filters are defined in the jsp pages.
c .Both of the above
D. None of the above
A
48. What are the mechanisms available in ServletContextListener interface?
a. contextInit(), contextService(), contextDestroyed()
b. contextInitialized((),contextDestroyed()
c. contextInitialized(), contextService(), contextDestroyed()
d. None of the above
B
49. Which deployment descriptor element is used to specify a ServletContext-
Listener? (Select one)
A . <context-listener>
B .<listener>
C .<servlet-context-listener>
D .None of the above
B
50. Which of the following is true about filters?
a. Servlet Filters are Java classes that can be used to intercept requests from a client
before they access a resource at back end
b. Servlet Filters are Java classes that can be used to manipulate responses from server
before they are sent back to the client
c. Not support in Servlet
A
51. Dynamic interception of requests and responses to transform the information is
done by
a. servlet container
b. servlet config
c. servlet context
d. servlet filter
D

You might also like