Week 8 Quiz Multiple Choice Flashcards
Given the following part of a configuration class, which line of code correctly retrieves the bean from the context?
@Bean(name=”myBeanName”)
public Student student(){
Return new Student();
}
Student student = (Student) context.getBean("myBeanName"); Student student = (Student) context.getBean("student"); Student student = context.getBean("Student"); Student student = (Student) context.getBean("mybeanname");
Student student = (Student) context.getBean(“myBeanName”);
Spring is
A dependency injection framework for JavaScript. A mocking library for Java. A JVM based programming language. A dependency injection framework for Java.
A dependency injection framework for Java.
A Spring bean is
The same as a Java bean. A class which is constructed and managed by Spring. Only classes defined in the Spring source code. Any bean annotated with @GetMapping.
A class which is constructed and managed by Spring.
The @Configuration annotation is used to
Provide XML configuration. Define a class as a configuration bean. Provide annotation driven configuration. Do the same as the @Autowired annotation.
Define a class as a configuration bean.
Which of the following is not a valid stereotype annotation?
@Component @Bean @Controller @Service
@Bean
In AOP, an aspect is
The modularization of a cross cutting concern. A location in code in which advice may be provided. A predicate expression used to match a join point. Implementation logic addressing cross cutting concerns.
A location in code in which advice may be provided.
In AOP, advice is
A location in code in which advice may be provided. The modularization of a cross cutting concern. Implementation logic addressing cross cutting concerns. A predicate expression used to match a join point.
A predicate expression used to match a join point.
Aspect oriented programming is a method of programming intended to address
Cross cutting concerns Aspects Isolated functionality Test driven development
Cross cutting concerns
The @RequestMapping annotation is used to
Provide a URL mapping to a resource for any HTTP method. Provide a URL mapping to a resource for only GET methods. Map a path variable to an array index. Provide data contained in a request body as a HashMap.
Provide a URL mapping to a resource for any HTTP method.
The @RequestBody annotation is used to
Define a class as a controller. Define that the return value of a method should be serialized to some form such as XML, JSON, ect. Define that the request body should be deserialized to a Java object from form such as XML, JSON, ect. Parse the a variable in the requested URL and injected to the method call as a parameter.
Define that the request body should be deserialized to a Java object from form such as XML, JSON, ect.
The @PathVariable annotation is used to
Define a class as a controller. Define that the return value of a method should be serialized to some form such as XML, JSON, ect. Define that the request body should be deserialized to a Java object from form such as XML, JSON, ect. Parse the a variable in the requested URL and injected to the method call as a parameter.
Parse the a variable in the requested URL and injected to the method call as a parameter.
When used on the class, the @RestController annotation implies what on all methods?
@ResponseBody @RequestBody @RequestMapping @RequestParam
@ResponseBody
The @Transactional annotation is used to
Define that the underlying code should be executed as a database transaction. Define that the underlying code is used to make a purchase. Define that the underlying code should never throw an exception. Does nothing.
Define that the underlying code should be executed as a database transaction.
Which of the following is not a way to get a bean from Spring?
Using the getBean method on the ApplicationContext or BeanFactory. Using @Autowire with a valid bean definition. Using an XML configuration with a valid bean reference. Using the @Aspect annotation before the declaration field, setter, or constructor.
Using an XML configuration with a valid bean reference.
Spring boot features an ‘opinionated configuration’ which means that:
It requires you to tell it how to configure all functionality. When not provided with configuration, it uses reasonable default configurations. It cannot be configured. You will never need to configure it.
When not provided with configuration, it uses reasonable default configurations.
Using the default configuration, Spring boot includes an embedded ________.
tomcat server postgres server in memory database user
tomcat server
What is Spring MVC?
A fully featured MVC framework that is a module of Spring. A module that provides for integration with Struts. Required for DI (Dependency Injection). Allows for component scanning through the component-scan tag in the applicationContext.xml.
A fully featured MVC framework that is a module of Spring.
What types of Dependency injection does spring supports?
Constructor based, Setter based Constructor based, Setter based, Getter Based Setter based, Getter based, Properties based Constructor based, Setter based, Properties based
Constructor based, Setter based
Explanation : Spring supports Constructor based, Setter based injections.
What is the current core container in Spring?
BeanFactory ApplicationContext WebContext XMLBeanFactory
ApplicationContext
Which of these is NOT a benefit of using Spring?
Your code is more decoupled Your code is more easily testable Cross-cutting concerns can be removed from application logic Testing your code isn't needed - the Spring container cannot inject a bean with bad data
Testing your code isn’t needed - the Spring container cannot inject a bean with bad data
The Spring Web MVC framework is designed around a _____ that handles all the HTTP requests and responses
HandlerMapping ViewResolver DispatcherServlet Controller
DispatcherServlet
This annotation registers the class as a controller and must be used in conjunction with tag in the XML to automatically discover and register the controllers as Spring beans.
@Controller @Handler @RequestMapping @Path
@Controller
What is Bean Factory?
A means for resolving text messages, including support for internationalization A class you define and create in your Spring application that implements the Factory design pattern Holds Bean Definitions of multiple beans within itself and then instantiates the bean when requested A Web GUI tool that allows you to access your bean definitions
Holds Bean Definitions of multiple beans within itself and then instantiates the bean when requested
Spring MVC uses which design pattern?
DAO Business Delegates Front Controller Flyweight
Front Controller
_____ advice executes if a method exits by throwing an exception.
Before After After returning After throwing Around
After throwing
_____ advice surrounds a join point such as a method invocation. This is the most powerful kind of advice.
Before After After returning After throwing Around
Around
_____ advice executes regardless of the means by which a join point exits (normal or exceptional return).
Before After After returning After throwing Around
After returning
____ advice executes before a join point, but does not have the ability to prevent execution flow proceeding to the join point (unless it throws an exception).
Before After After returning After throwing Around
Before
Which of the following is not a valid HTTP method used in REST
OPTIONS DELETE DATE POST
DATE
Explanation : DATE is not a HTTP Verb and is not a valid HTTP methods used in RESTful web services.
What is a resource in REST?
Any content accessible through the Web Service A socket connection to access the Web Service A database connection object for the service to access its data All of the above
Any content accessible through the Web Service
What message protocol is used in REST?
SMTP HTTP FTP All of the above
HTTP
What does REST stand for?
Representational State Transfer Representational Structured Transfer Representational System Transfer Representational State Translation
Representational State Transfer
How are exceptions handled in REST?
A web service should pass back an Exception object to the client A web service should use HTTP error codes like 403 to show access forbidden using the Response object Using faults like the way SOAP does Exceptions should not be sent back to the client
A web service should use HTTP error codes like 403 to show access forbidden using the Response object
REST - statelessness
RESTful APIs should be:
Stateless Stateful
Stateless
What is contained in an HTTP Request?
Select all that apply from the following:
Headers containing metadata
A verb
A body, potentially containing data
A destination URL
A response
An HTML form
Headers containing metadata,
A body, potentially containing data,
A destination URL
Which of the following HTTP Status code means INTERNAL SERVER ERROR, states that server has thrown some exception while executing the method?
500 401 404 409
500
Explanation : HTTP Status Code 500 means INTERNAL SERVER ERROR, states that server has thrown some exception while executing the method.
Which is not one of the core components of an HTTP response?
Response Header Response Body HTTP Version Status Code URI
URI