click below
click below
Normal Size Small Size show me how
Spring Basics
An introduction to the basic concepts of the Java Spring Framework.
Question | Answer |
---|---|
An application framework implements the standard ____________ of an application for a specific development environment. | structure |
In frameworks, _____________ help to assemble components from different projects into a cohesive application. | containers |
Frameworks often play the role of the main program in coordinating and sequencing application activity ("don't call us; we'll call you"); this characteristic is referred to as _______________. | inversion of control |
A framework is essentially a ____________, a structure around which the fleshing-out of an application occurs. | skeleton |
An ___________ is a group of method declarations with empty bodies, whose behavior is implemented in a separate class. | interface |
The pattern of __________ relies on the concept of an "assembler" that instantiates the objects required by an application and “injects” them into their dependent objects. | dependency injection |
Types of Dependency Injection: In __________, the constructor arguments are injected during instance instantiation. | constructor injection |
Types of Dependency Injection: In _________, dependencies are "set" in the objects through setter methods defined in a Spring configuration file. | setter injection |
Types of Dependency Injection: In ___________, (not currently implemented in Spring), items are mapped to inject to specific interfaces. | interface injection |
Spring uses the concept of a ___________ as its assembler, which manages the JavaBeans the developer has configured to run within it. | BeanFactory |
In Spring, the initialization of a bean by the framework is exactly equivalent to using the ______ keyword to instantiate an object in Java code. | new |
Coding to __________ is part of good object-oriented practice. | interfaces |
In Spring, bean configuration is accomplished by ___________. | XML mapping |
The core module of the Spring framework is its __________ container. | inversion of control |
The inversion of control container manages Java objects from instantiation to destruction through its _________ (assembler). | BeanFactory |
Java components that are instantiated by the inversion of control container are called _______. | beans |
Setter injection uses the ______ methods in a class file to garner property names that are configurable in the XML configuration file. | set |
The implementation of the inversion of control container that should be used when building an application is _______________. | ApplicationContext |
The __________ is a subclass of the BeanFactory interface, so it has all the functionality a BeanFactory has and more. | ApplicationContext |
A popular implementation of ApplicationContext, which defaults to reading resources from the classpath, is ____________. | ClassPathXmlApplicationContext |
A __________ is a parameter that tells the Java Virtual Machine or the Java compiler where to look for user-defined classes and packages. | classpath |
The key benefit of dependency injection is that it removes the dependency that a given class has on a particular _____________. | implementation |
Dependency injection simplifies object-oriented programming by promoting ____________ between classes. | loose coupling |
Spring's core model of dependency injection lets the developer define which __________ are created and what their ___________ are. | beans; properties |
A major module of Spring, __________, refers to the ability to add side effects to a class's method calls without modifying the class's source code. | aspect-oriented programming |
The basic philosophy of Spring is to avoid __________ among classes. | tight coupling |
The Spring framework is composed of several well-defined ___________ built on top of the core __________, making it possible to use as much or as little of the Spring framework as is needed in a particular application. | modules; container |
Objects whose implementations are likely to change are defined in the _________ file. | bean definition |
In the bean definition file, the _________ tag is used to define an object's name and class. | bean |
In the bean definition file, the _________ tag is used to assign values to the object (setter injection). | property |
In the bean definition file, the ________ tag is used to assign values to the object (constructor injection). | constructor-arg |
The following code creates a new __________ based on a bean definition file: ApplicationContext context = new ClassPathXmlApplicationContext("/bean-file.xml") | container |
The following code gets _____________ from the container: (InterfaceType)context.getBean("bean-name") | object instances |
Spring is useful when you have objects whose ____________ change often, and you supply _____________ values through constructors or setter methods. | implementations; initialization |
Bean initialization values can be other beans instead of concrete values; supplying these values in a definition file to be passed at runtime is known as _____________. | dependency injection |
Basic Spring Applications, Step #1: Define an ___________ or __________ with no dependencies on Spring. | interface; abstract class |
Basic Spring Applications, Step #2: Make concrete ______________ of the _____________. | implementations; interface |
Basic Spring Applications, Step #3: Declare concrete __________ in ______________ file. | object; bean definition |
Basic Spring Applications, Step #4: Instantiate _____________ from _____________ file. | container; bean definition |
Basic Spring Applications, Step #5: Get __________ instances. | bean |
When you declare a bean (and don't use constructor-arg), the _______________ is called when the object is instantiated. | zero-argument constructor |
The bean definition file refers to a "bean property", which is a shortcut for a ________ method name. | setter |
The bean property name is determined by dropping ______ from the setter method name, then changing the next letter to __________. | set; lowercase |
The property and constructor-arg tags have an attribute, ________, which refers to a bean declared elsewhere. | ref |
bean tags can be __________ to supply a new bean as a value to a setter method or constructor. | nested |
list tags can be nested inside property or constructor-arg tags to pass a ________ to a setter method or constructor. | list |
map tags can be nested inside property or constructor-arg tags to pass a ________ to a setter method or constructor. | map |
Instantiating the ________________ container is expensive and should be done once only. | ApplicationContext |
Instead of calling the zero-argument constructor and then calling setter methods, you can supply ___________ arguments. | constructor |
Use ___________ only for immutable classes that have no setter methods. Use _________ otherwise. | constructor-arg; property |
One issue with constructor arguments is that Spring does not always pass arguments in the _________ that they are listed. | order |
One issue with constructor arguments is that Spring does type conversion, so arguments that are _____________ with the constructor definition could still be accepted. | mismatched |
Setter injection is often preferred over constructor injection because constructor-arg is prone to ___________. | ambiguity |
If there are multiple constructor arguments with compatible types, the _________ attribute can be used to specify which argument is which (e.g. <constructor-arg value="5" index="0"/>). | index |
If there are multiple constructors with same number of arguments, both _________ and __________ attributes can be used (e.g. constructor-arg value="5" index="0" type="int"). | index; type |
If you don't know what type of bean you will need, you can call a ___________ method. | factory |
The misnamed _____________ can be used to supply values to the factory method. | constructor-arg |
In order to avoid dependencies, the main class should never call ______ on a particular subclass. Instead, the bean definition file should create the objects that the main class depends on and inject them into the main class via _________ or ___________. | new; property; constructor-arg |
Spring allows Collections to be injected; it is possible to pass a __________ or __________ of beans. | list; map |
To use an existing bean as a property in a bean definition, use the _______ tag (the same applies to using an existing bean as a constructor-arg). | ref |
To pass a list to a bean, nest the _______ tags inside the property tags, and use the ________ tag to contain the existing bean name. | list; ref local |
To pass a map to a bean, nest the _______ tags inside the property tags, and use the ________ tag to contain the existing bean name. | map; entry key |
If you do not define _________, every time you call getBean() on the same name, you get the same instance. | scope |
The property and constructor-arg tags are only invoked the first time a bean is called; e.g., if a bean of that name has not already been ____________. | instantiated |
To get a new instance of a bean every time it is called, use the attribute/value __________ within the bean definition. | scope = "prototype" |
Beans in web applications can have various scopes in addition to default and prototype, including __________ and ___________. | request; session |