Core Technologies Flashcards

1
Q

What is the Inversion of Control (IoC) principle?

A

IoC is also known as dependency injection (DI). It is a process whereby objects define their dependencies instead of creating them themselves. Code is cleaner with the DI principle, and decoupling is more effective when objects are provided with their dependencies

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the difference between the interfaces BeanFactory and ApplicationContext?

A

The BeanFactory interface provides an advanced configuration mechanism capable of managing any type of object. ApplicationContext is a sub-interface of BeanFactory

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a Bean in Spring?

A

A bean is an object that is instantiated, assembled, and managed by a Spring IoC container. Otherwise, a bean is simply one of many objects in your application. Beans, and the dependencies among them, are reflected in the configuration metadata used by a container.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the flow of Spring DI Container?

A

It recieves POJOs and Configuration metadata and it produces a fully-configured ready-to-use system.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is Configuration metadata?

A

It represents how you, as an application developer, tell the Spring container to instantiate, configure, and assemble the objects in your application. It can be supplied using XML or Annotations.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is the role of BeanDefinition?

A

Each BeanDefinition object stores information about a bean. Examples of properties are class, name and scope.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How the container identifies a Bean?

A

The container identifies a bean using identifiers. Each bean have one or more identifiers.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the two DI variants and which one should I use?

A

Constructor-based and Setter-based Dependency Injection. The Spring team generally advocates constructor injection, as it lets you implement application components as immutable objects and ensures that required dependencies are not null. Furthermore, constructor-injected components are always returned to the client (calling) code in a fully initialized state.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is autowiring?

A

It’s a mechanism whereby Spring resolve collaborators (other beans) automatically for your bean by inspecting the contents of the ApplicationContext. It has two main advantages:

Autowiring can significantly reduce the need to specify properties or constructor arguments.

Autowiring can update a configuration as your objects evolve

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What ApplicationContextAware is used for?

A

The ApplicationContextAware interface is implemented when a bean needs to access the ApplicationContext.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Which are the two main types of Bean Scopes?

A

Singleton (Default). One bean for the whole container.

Prototype. Creates one bean everytime is used.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What BeanNameAware is used for?

A

The BeanNameAware interface is implemented when tthe a bean needs to modify its name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the @Import Annotation used for?

A

It is mainly used for creating composed configuration, reducing bean definition complexity. It accepts an array of classes that are usually annotated with the @Configuration annotation.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a Spring profile?

A

A profile is a named, logical group of bean definitions to be registered with the container only if the given profile is active.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is the @Profile Annotation used for?

A

The @Profile annotation lets you indicate that a component is eligible for registration when one or more specified profiles are active.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the limitations of autowiring?

A

Autowiring is less exact than explicit wiring. Although, as noted in the earlier table, Spring is careful to avoid guessing in case of ambiguity that might have unexpected results.

The relationships between your Spring-managed objects are no longer documented explicitly.

Wiring information may not be available to tools that may generate documentation from a Spring container.

17
Q

What are the Stereotype Annotations ?

A

They are annotations used by Spring to autowire beans. All of them are class-level annotations.

Some examples are @Component, @Service, @Repository and @Controller

18
Q

What are the benefits of the Spring Resource class ?

A

Spring’s Resource interface is meant to be a more capable interface for abstracting access to low-level resources. It is an alternative to the java.net.URL.