Java MCQ Set 1
1. To publish a REST service with Spring.
a) publishing an application’s data as a REST service
b) accessing data from third-party REST services
c) none of the mentioned
d) all of the mentioned
Answer
Answer: d [Reason:] One involves publishing an application’s data as a REST service, the other one involves accessing data from third-party REST services to be used in an application.
2. Publishing an application’s data as a REST service requires.
a) @RequestMapping
b) @PathVariable
c) All of the mentioned
d) None of the mentioned
Answer
Answer: c [Reason:] Publishing an application’s data as a REST service revolves around the use of the Spring MVC annotations @RequestMapping and @PathVariable.
3. Spring supports a series of mechanisms to generate a REST service’s payload.
a) True
b) False
Answer
Answer: a [Reason:] This recipe will explore the simplest mechanism, which involves the use of Spring’s MarshallingView class.
4. Annotation added as an input parameter to the handler method.
a) @PathVariable
b) @Path
c) @PathLocale
d) None of the mentioned
Answer
Answer: a [Reason:] The @PathVariable annotation is added as an input parameter to the handler method, per Spring’s MVC conventions, in order for it to be used inside the handler method body.
5. Notation for defining REST end points.
a) { }
b) *
c) All of the mentioned
d) None of the mentioned
Answer
Answer: c [Reason:] In addition to supporting the { } notation, it’s also possible to use a wildcard * notation for defining REST end points.
6. General-purpose class that allows a response to be rendered using a marshaller.
a) MarshallingView
b) Marshalling
c) View
d) All of the mentioned
Answer
Answer: a [Reason:] The membertemplate view is defined as a MarshallingView type, which is a general-purpose class that allows a response to be rendered using a marshaller.
7. Marshalling is the process of transforming an in-memory representation of an object into a data format.a
a) True
b) False
Answer
Answer: a [Reason:] Therefore, for this particular case, a marshaller is charged with transforming a Member object into an XML data format.
8. The marshaller used by MarshallingView belongs to one of a series of XML marshallers.
a) Jaxb2Marshaller
b) XmlBeansMarshaller
c) CastorMarshalle
d) All of the mentioned
Answer
Answer: d [Reason:] The marshaller used by MarshallingView belongs to one of a series of XML marshallers provided by Spring—Jaxb2Marshaller. Other marshallers provided by Spring include CastorMarshaller, JibxMarshaller, XmlBeansMarshaller, and XStreamMarshaller.
9. To configure Jaxb2Marshaller marshaller we require.
a) ClassesToBeBound
b) ContextPath
c) All of the mentioned
d) None of the mentioned
Answer
Answer: c [Reason:] The Jaxb2Marshaller marshaller requires to be configured with either a property named classesToBeBound or contextPath.
10. In the case of classesToBeBound, the classes assigned to this property, indicate the class (i.e., object) structure that is to be transformed into XML.
a) True
b) False
Answer
Answer: a [Reason:] The Jaxb2Marshaller marshaller requires to be configured with either a property named classesToBeBound or contextPath.
11. Annotation which allows the Jaxb2Marshaller marshaller to detect a class’s (i.e., object’s) fields.
a) @XmlRootElement
b) @XmlRoot
c) @NotNull
d) None of the mentioned
Answer
Answer: a [Reason:] This annotation allows the Jaxb2Marshaller marshaller to detect a class’s (i.e., object’s) fields and transform them into XML data.
12. Accessing a third-party REST service inside a Spring application.
a) RestTemplate Class
b) ViewResolver
c) InternalViewResolver
d) View
Answer
Answer: a [Reason:] Accessing a third-party REST service inside a Spring application revolves around the use of the Spring RestTemplate class.
13. REST service end point comprises an address.
a) starts with http:// and ends with ?
b) starts with http:// and ends with &
c) no certain URL is specified
d) depends upon the platform used
Answer
Answer: a [Reason:] The structure of the REST service end point comprises an address, which starts with http:// and ends with ?, as well as a series of parameters that start with ? and are delimited by &, each represented by a key and value divided by =.
14. XML tag which represents information related to a REST service’s request.
a) Result
b) Title
c) None of the mentioned
d) All of the mentioned
Answer
Answer: d [Reason:] The actual meaning of the payload is highly dependent on a REST service. In this case, the XML tags (e.g., Result, Title ) are definitions set forth by Yahoo, while the character data enclosed in each XML tag represents information related to a REST service’s request.
15. RestTemplate class method which performs an HTTP HEAD operation.
a) headForHeaders(String, Object…)
b) getForObject(String, Class, Object…)
c) postForLocation(String, Object, Object…)
d) postForObject(String, Object, Class, Object…)
Answer
Answer: a [Reason:] headforHeaders() is a RestTemplate class method based on HTTP protocol’s request methods.
Java MCQ Set 2
1. To publish a REST service with Spring.
a) publishing an application’s data as a REST service
b) accessing data from third-party REST services
c) none of the mentioned
d) all of the mentioned
Answer
Answer: d [Reason:] One involves publishing an application’s data as a REST service, the other one involves accessing data from third-party REST services to be used in an application.
2. Publishing an application’s data as a REST service requires.
a) @RequestMapping
b) @PathVariable
c) All of the mentioned
d) None of the mentioned
Answer
Answer: c [Reason:] Publishing an application’s data as a REST service revolves around the use of the Spring MVC annotations @RequestMapping and @PathVariable.
3. Spring supports a series of mechanisms to generate a REST service’s payload.
a) True
b) False
Answer
Answer: a [Reason:] This recipe will explore the simplest mechanism, which involves the use of Spring’s MarshallingView class.
4. Annotation added as an input parameter to the handler method.
a) @PathVariable
b) @Path
c) @PathLocale
d) None of the mentioned
Answer
Answer: a [Reason:] The @PathVariable annotation is added as an input parameter to the handler method, per Spring’s MVC conventions, in order for it to be used inside the handler method body.
5. Notation for defining REST end points.
a) { }
b) *
c) All of the mentioned
d) None of the mentioned
Answer
Answer: c [Reason:] In addition to supporting the { } notation, it’s also possible to use a wildcard * notation for defining REST end points.
6. General-purpose class that allows a response to be rendered using a marshaller.
a) MarshallingView
b) Marshalling
c) View
d) All of the mentioned
Answer
Answer: a [Reason:] The membertemplate view is defined as a MarshallingView type, which is a general-purpose class that allows a response to be rendered using a marshaller.
7. Marshalling is the process of transforming an in-memory representation of an object into a data format.a
a) True
b) False
Answer
Answer: a [Reason:] Therefore, for this particular case, a marshaller is charged with transforming a Member object into an XML data format.
8. The marshaller used by MarshallingView belongs to one of a series of XML marshallers.
a) Jaxb2Marshaller
b) XmlBeansMarshaller
c) CastorMarshalle
d) All of the mentioned
Answer
Answer: d [Reason:] The marshaller used by MarshallingView belongs to one of a series of XML marshallers provided by Spring—Jaxb2Marshaller. Other marshallers provided by Spring include CastorMarshaller, JibxMarshaller, XmlBeansMarshaller, and XStreamMarshaller.
9. To configure Jaxb2Marshaller marshaller we require.
a) ClassesToBeBound
b) ContextPath
c) All of the mentioned
d) None of the mentioned
Answer
Answer: c [Reason:] The Jaxb2Marshaller marshaller requires to be configured with either a property named classesToBeBound or contextPath.
10. In the case of classesToBeBound, the classes assigned to this property, indicate the class (i.e., object) structure that is to be transformed into XML.
a) True
b) False
Answer
Answer: a [Reason:] The Jaxb2Marshaller marshaller requires to be configured with either a property named classesToBeBound or contextPath.
11. Annotation which allows the Jaxb2Marshaller marshaller to detect a class’s (i.e., object’s) fields.
a) @XmlRootElement
b) @XmlRoot
c) @NotNull
d) None of the mentioned
Answer
Answer: a [Reason:] This annotation allows the Jaxb2Marshaller marshaller to detect a class’s (i.e., object’s) fields and transform them into XML data.
12. Accessing a third-party REST service inside a Spring application.
a) RestTemplate Class
b) ViewResolver
c) InternalViewResolver
d) View
Answer
Answer: a [Reason:] Accessing a third-party REST service inside a Spring application revolves around the use of the Spring RestTemplate class.
13. REST service end point comprises an address.
a) starts with http:// and ends with ?
b) starts with http:// and ends with &
c) no certain URL is specified
d) depends upon the platform used
Answer
Answer: a [Reason:] The structure of the REST service end point comprises an address, which starts with http:// and ends with ?, as well as a series of parameters that start with ? and are delimited by &, each represented by a key and value divided by =.
14. XML tag which represents information related to a REST service’s request.
a) Result
b) Title
c) None of the mentioned
d) All of the mentioned
Answer
Answer: d [Reason:] The actual meaning of the payload is highly dependent on a REST service. In this case, the XML tags (e.g., Result, Title ) are definitions set forth by Yahoo, while the character data enclosed in each XML tag represents information related to a REST service’s request.
15. RestTemplate class method which performs an HTTP HEAD operation.
a) headForHeaders(String, Object…)
b) getForObject(String, Class, Object…)
c) postForLocation(String, Object, Object…)
d) postForObject(String, Object, Class, Object…)
Answer
Answer: a [Reason:] headforHeaders() is a RestTemplate class method based on HTTP protocol’s request methods.
Java MCQ Set 3
1. Element which secures web flows.
a) secured
b) security
c) sec
d) none of the mentioned
Answer
Answer: a [Reason:] With Spring Security configured properly, you can simply secure a flow, a state, or a transition by embedding the secured element with required access attributes specified.
2. To secure web flows with Spring Security.
a) DelegatingFilter
b) DelegatingFilterProxy
c) DelegatingProxy
d) None of the mentioned
Answer
Answer: b [Reason:] To secure web flows with Spring Security, you first have to configure a DelegatingFilterProxy filter in the web deployment descriptor (i.e., web.xml).
3.
<dependency> <groupId></groupId> <artifactId>spring-security-core</artifactId> <version>3.0.2.RELEASE</version> </dependency>
Group id to add spring security using Maven.
a) org.springframework.secure
b) org.springframework.security
c) org.springframework.securedflow
d) none of the mentioned
Answer
Answer: b [Reason:] org.springframework.secur is ued to secure web flows with Spring Security.
4. auto-config provides only default form-based login service.
a) True
b) False
Answer
Answer: b [Reason:] HTTP auto-config, which provides a default form-based login service, an anonymous login service, and so on.
5. To enable Spring security for web flows.
a) SecurityFlowExecutionListener
b) SecurityFlowExecution
c) FlowSecurity
d) SecurityFlowListener
Answer
Answer: a [Reason:] You have to register the flow execution listener SecurityFlowExecutionListener in the flow executor to enable Spring Security for web flow.
6.
<beans ...> ... <webflow:flow-executor id="flowExecutor"> <webflow:flow-execution-listeners> <webflow:listener ref="securityFlowExecutionListener" /> </webflow:flow-execution-listeners> </webflow:flow-executor> <bean id="securityFlowExecutionListener" class="?" /> </beans>
Which of the following class should replace ‘?’.
a) org.springframework.webflow.security.SecurityFlow
b) org.springframework.webflow.SecurityFlowExecutionListener
c) org.springframework.webflow.security.SecurityFlowExecutionListener
d) org.springframework.security.SecurityFlowExecutionListener
Answer
Answer: c [Reason:] You have to register the flow execution listener SecurityFlowExecutionListener in the flow executor to enable Spring Security for web flow.
7. Which attribute is used to access security element od web flow.
a) attribute
b) attributes-security
c) attributes
d) none of the mentioned
Answer
Answer: c [Reason:] You can specify multiple access attributes required for accessing this web flow in the attributes attribute, separated by commas.
8. Spring web flow supports integration with.
a) JSF
b) Hibernate
c) JPA
d) All of the mentioned
Answer
Answer: d [Reason:] Spring Web Flow 2.0 comes with support for JPA and Hibernate.
9. To integrate JPA with Spring Web flows.
a) JpaFlowExecutionListener
b) HibernateFlowExecutionListener
c) All of the mentioned
d) None of the mentioned
Answer
Answer: a [Reason:] To have Spring Web Flow manage the persistence contexts for your web flows, you have to register a flow execution listener (e.g., JpaFlowExecutionListener for JPA.
10. To integrate Hibernate with Spring Web flows.
a) JpaFlowExecutionListener
b) HibernateFlowExecutionListener
c) All of the mentioned
d) None of the mentioned
Answer
Answer: b [Reason:] To have Spring Web Flow manage the persistence contexts for your web flows, you have to register a flow execution listener (e.g., HibernateFlowExecutionListener for Hibernate.
11. HibernateFlowExecutionListener and JpaFlowExecutionListener both belongs to which of the package.
a) org.springframework.web.persistence package
b) org.springframework.persistence package
c) org.springframework.webflow package package
d) org.springframework.webflow.persistence package
Answer
Answer: d [Reason:] JpaFlowExecutionListener for JPA and HibernateFlowExecutionListener for Hibernate, both of which belong to the org.springframework.webflow.persistence package) in the flow executor.
12. JpaFlowExecutionListener and Hibernate Listener binds to flow scope.
a) True
b) False
Answer
Answer: a [Reason:] . When a new flow starts, this listener creates a new persistence context (e.g., a JPA entity manager or a Hibernate session) and binds it to the flow scope.
13. Libraries used to integrate Hibernate with JPA.
a) Hibernate 3
b) Hibernate 3 Entity Manager
c) JPA API
d) All of the mentioned
Answer
Answer: d [Reason:] To use Hibernate as the JPA engine, you have to add Hibernate 3, the Hibernate 3 EntityManager, the JPA API, and ehcache.
14. To configure JPA vendor-specific information.
a) JPA vendor adaptor
b) Data source
c) All of the mentioned
d) None of the mentioned
Answer
Answer: c [Reason:] you can configure a JPA entity manage factory by providing a data source and a JPA vendor adaptor, where you can configure JPA vendor-specific information.
15. You have to register a flow execution listener in the flow executor.
a) True
b) False
Answer
Answer: a [Reason:] To have Spring Web Flow manage the persistence contexts for your web flows, you have to register a flow execution listener in the flow executor.
Java MCQ Set 4
1. Way to secure web app’s URL.
a) servlet filters
b) refresh-check-delay
c) http servlet filters
d) none of the mentioned
Answer
Answer: a [Reason:] Spring Security enables you to secure a web application’s URL access in a declarative way through simple configuration. It handles security by applying servlet filters to HTTP requests.
2. Servlet filter registered in web deployment descriptor, which filters request in spring application context.
a) DelegatingFilter
b) DelegatingFilterProxy
c) DelegatingProxy
d) None of the mentioned
Answer
Answer: b [Reason:] As servlet filters must be registered in the web deployment descriptor to take effect, you have to register a DelegatingFilterProxy instance in the web deployment descriptor, which is a servlet filter that delegates request filtering to a filter in Spring’s application context.
3. Servlet APIs to access security information of web application.
a) HttpServletRequest.isUserInRole()
b) HttpServletRequest.getUserPrincipal()
c) None of the mentioned
d) All of the mentioned
Answer
Answer: d [Reason:] Servlet API integration: This allows you to access security information in your web application via standard Servlet APIs, such as HttpServletRequest.isUserInRole() and HttpServletRequest.getUserPrincipal().
4. To load root application context at the start up.
a) ContextListener
b) ContextLoader
c) ContextLoaderListener
d) ContextEventListener
Answer
Answer: c [Reason:] In the web deployment descriptor (i.e., web.xml), you register ContextLoaderListener to load the root application context at startup.
5. To dispatch requests for web application.
a) DispatcherServlet
b) ViewHandler
c) ViewResolver
d) None of the mentioned
Answer
Answer: a [Reason:] Spring MVC’s DispatcherServlet is used to dispatch requests.
6. The responsibility of DelegatingFilterProxy is simply to delegate HTTP request filtering to a Spring bean that implements the interface:-
a) java.util.logging.Filter
b) java.util.logging.net
c) java.util.logging.FilterHttp
d) none of the mentioned
Answer
Answer: a [Reason:] The responsibility of DelegatingFilterProxy is simply to delegate HTTP request filtering to a Spring bean that implements the java.util.logging.Filter interface.
7. By default, DelegatingFilterProxy delegates to a bean whose name is the same as its filter-name property.
a) True
b) False
Answer
Answer: a [Reason:] By default, it delegates to a bean whose name is the same as its filter-name property, but you can override the bean name in its targetBeanName init parameter.
8. Filter chain configured by Spring security, when web app security enabled.
a) springSecurityFilterChain
b) delegatingFilterProxy
c) none of the mentioned
d) all of the mentioned
Answer
Answer: a [Reason:] As Spring Security will automatically configure a filter chain with the name springSecurityFilterChain when you enable web application security, you can simply use this name for your DelegatingFilterProxy instance.
9. The http auto-config=”false” element automatically configures the basic security services that a typical web application needs.
a) True
b) False
Answer
Answer: b [Reason:] The http auto-config=”true” element automatically configures the basic security services that a typical web application needs. You can fine-tune these services with the corresponding subelements inside it.
10. Element used to restrict access to a particular URL.
a) restrict-url
b) intercept-url
c) intercept-restrict
d) none of the mentioned
Answer
Answer: b [Reason:] Inside the http configuration element, you can restrict access to particular URLs with one or more intercept-url elements.
11. Element which configures authentication services.
a) authentication-provider
b) authentication-manager
c) all of the mentioned
d) none of the mentioned
Answer
Answer: c [Reason:] You can configure authentication services in the authentication-provider element, which is nested inside the authentication-manager element.
12. Element which defines user details.
a) user-service
b) user-details
c) user-requirements
d) user-servicerequirements
Answer
Answer: a [Reason:] Spring Security also supports defining user details in user-service directly for simple security requirements. You can specify a
username, a password, and a set of authorities for each user.
13. Which of the following way to provide authenticity of users is/are supported by Spring Security?
a) Authenticating against a database
b) LDAP repository
c) All of the mentioned
d) None of the mentioned
Answer
Answer: c [Reason:] Spring Security supports several ways of authenticating users, including authenticating against a database or an LDAP repository.
14. The basic security services registered and configured by Spring Security.
a) Form-based login service
b) Logout Service
c) HTTP Basic authentication.
d) All of the mentioned
Answer
Answer: d [Reason:] Spring Security will automatically register and configure several basic security services, including the above mentioned.
15. HTTP Basic authentication support is configured by:-
a) logout
b) http-basic
c) http-basicauth
d) none of the mentioned
Answer
Answer: d [Reason:] The HTTP Basic authentication support can be configured via the http-basic element. When HTTP Basic authentication is required, a browser will typically display a login dialog or a specific login page for users to log in.
Java MCQ Set 5
1. Form-based login is configured by:-
a) servlet filters
b) refresh-check-delay
c) form-login
d) none of the mentioned
Answer
Answer: c [Reason:] The form-based login service will render a web page that contains a login form for users to input their login details and process the login form submission. It’s configured via the form-login element.
2. Action URL can be customized using form-login.
a) True
b) False
Answer
Answer: a [Reason:] Note that the form action URL and the input field names are Spring Security–specific. However, the action URL can be customized with the login-url attribute of form-login.
3. Attribute used to display custom login page.
a) login-url
b) custom-login
c) login-custom
d) custom-login
Answer
Answer: a [Reason:] In order for Spring Security to display your custom login page when a login is requested, you have to specify its URL in the login-page attribute.
4. Attribute which sepcifies redirection URL on login error.
a) authentication-failure-url
b) authentication-failure_login-url
c) authentication-login-url
d) none of the mentioned
Answer
Answer: a [Reason:] If you specify a custom login page, you will have to configure the authentication-failure-url attribute to specify which URL to redirect to on login error.
5. Session scope attribute to display error message.
a) SPRING_SECURITY_FIRST_EXCEPTION
b) SPRING_SECURITY_LAST_EXCEPTION
c) SPRING_SECURITY_EXCEPTION
d) SPRING_SECURITY_LAST_ERROR
Answer
Answer: b [Reason:] If an error has occurred, you will have to display the error message by accessing the session scope attribute SPRING_SECURITY_LAST_EXCEPTION, which stores the last exception for the current user.
6. Logout service is configured by:-
a) logout
b) login
c) logout-basic
d) logout_basic
Answer
Answer: a [Reason:] The logout service provides a handler to handle logout requests. It can be configured via the logout element.
7. Element which redirects to a specific URL on logout.
a) logout-success
b) logout-success_url
c) logout-url
d) logout-success-url
Answer
Answer: d [Reason:] By default, a user will be redirected to the context path’s root when the logout succeeds, but sometimes, you may wish to direct the user to another URL.
8. Anonymous login services can be configured by:-
a) anonymous-basic
b) anonymous
c) anonymous-target
d) none of the mentioned
Answer
Answer: b [Reason:] The anonymous login service can be configured via the anonymous element.
9. Default values of customized Username and authorities are anonymousUser and ROLE_ANONYMOUS respectively.
a) True
b) False
Answer
Answer: a [Reason:] You can customize the username and authorities of an anonymous user, whose default values are anonymousUser and ROLE_ANONYMOUS.
10. Remember-me support can be configured by:-
a) remember-me
b) remember-me-basic
c) remember-basic
d) none of the mentioned
Answer
Answer: a [Reason:] Remember-me support can be configured via the remember-me element.
11. By default, Remember-me encodes the username, password, remember-me expiration time, and a private key as a token, and stores it as a cache in the user’s browser.
a) True
b) False
Answer
Answer: b [Reason:] Remember-me stores as cookie in the user’s browser not as cache.
12. Spring Security algorithms to secure password.
a) MD5
b) SHA
c) All of the mentioned
d) None of the mentioned
Answer
Answer: c [Reason:] Spring Security supports several algorithms for encoding passwords (including MD5 and SHA) and provides built-in password encoders for these algorithms.
13. Connection of database with Apache derby server requires.
a) Derby client.jar
b) Spring JDBC support
c) None of the mentioned
d) All of the mentioned
Answer
Answer: d [Reason:] To connect to a database in the Apache Derby server, you need the Derby client .jars, as well as the Spring JDBC support.
14. You can specify the statements for querying a user’s information and authorities in the users-by-username-query and authorities-by-username-query attributes.
a) True
b) False
Answer
Answer: a [Reason:] Spring Security also supports using custom SQL statements to query a legacy database for user details.
15. Utility to calculate MD5 digests for your password.
a) CheckSum
b) BeanShell
c) Jacksum
d) None of the mentioned
Answer
Answer: c [Reason:] Jacksum, which you can download from http://sourceforge.net/projects/jacksum/ and extract to a directory of your choice. Then execute the following command to calculate a digest for a text:
java -jar jacksum.jar -a md5 -q “txt:secret”