Intro to Spring Framework Flashcards

1
Q

How does a framework differ from a library?

A

A framework dictates the overall architecture, controls the flow of the application, and imposes certain rules, while a library offers specific functionalities that developers can use as needed within their applications.

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

What is coherence in a software system?

A

Coherence refers to the state where all components of a software system work together seamlessly, maintaining consistency and uniformity in their behavior and interactions.

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

How can consistent coding practices contribute to coherence?

A

Adopting consistent coding standards, naming conventions, and design patterns across the software system ensures uniformity, readability, and easier collaboration among developers.

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

How does centralized data management contribute to system coherence?

A

Centralized data management ensures that all parts of the system access and modify data consistently, avoiding conflicts and discrepancies in information across different components.

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

What is Dependency Injection (DI)?

A

Dependency Injection is a design pattern where the dependencies of a component are provided or “injected” from the outside rather than created within the component itself.

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

What problem does Dependency Injection aim to solve?

A

Dependency Injection addresses tight coupling between components by removing their direct dependencies on other components or services, making them more reusable and easier to maintain.

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

What are the key components in Dependency Injection?

A

In DI, there are typically three main components: the client or consumer that requires a service or dependency, the service or dependency itself, and the injector that provides the dependency to the client.

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

What are the types of Dependency Injection?

A

There are primarily three types of DI: Constructor Injection, Setter Injection, and Interface Injection. Constructor Injection and Setter Injection are the most commonly used forms.

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

What are the benefits of Dependency Injection?

A

DI promotes code reusability, testability, and easier maintenance by reducing coupling between components, making the application more flexible and easier to extend or modify.

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

How is dependency achieved between classes through an interface in Java?

A

In Java, dependency between classes through an interface is established by having a class implement an interface, and another class consuming that interface.

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

What is an example of an interface in Java that defines a contract?

A

// Example of an interface defining a contract
public interface MessagingService {
void sendMessage(String message);
}

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

How can a class implement an interface in Java?

A

// Example of a class implementing an interface
public class EmailService implements MessagingService {
@Override
public void sendMessage(String message) {
// Implementation specific to sending emails
System.out.println(“Sending email: “ + message);
}
}

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

How can another class depend on the interface rather than the concrete implementation?

A

// Example of a class depending on the interface
public class NotificationService {
private MessagingService messagingService;

// Constructor or setter for dependency injection
public NotificationService(MessagingService messagingService) {
    this.messagingService = messagingService;
}

public void sendNotification(String message) {
    // Using the interface method, unaware of the concrete implementation
    messagingService.sendMessage(message);
} }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How does this approach aid in flexibility and extensibility?

A

By depending on the MessagingService interface, NotificationService can be easily switched to use different implementations (e.g., EmailService, SMSService) without modifying its code.

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

What is the Dependency Inversion Principle (DIP)?

A

The Dependency Inversion Principle is a design principle that states that high-level modules/classes should not depend on low-level modules/classes. Instead, both should depend on abstractions.

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

What are the two key aspects of Dependency Inversion?

A

Dependency Inversion involves two key aspects: Abstraction and Inversion of Control (IoC) (IoC - a framework doing DI on your behalf ), where abstractions are used to decouple high-level modules from concrete implementations, and IoC containers manage dependencies.

17
Q

How does Dependency Inversion relate to interfaces and abstractions?

A

In DIP, interfaces or abstractions are used to define contracts between modules/classes, allowing different implementations to adhere to those contracts without affecting higher-level modules.

18
Q

What benefits does Dependency Inversion offer in terms of testing?

A

Dependency Inversion facilitates easier unit testing by allowing the substitution of dependencies with mock objects or stubs, enabling isolated testing of individual components.

19
Q

How are Spring Beans created and managed?

A

Spring Beans are created, configured, and managed by the Spring IoC container, which handles their lifecycle, dependencies, and instantiation based on the configuration provided.

20
Q

How are Spring Beans defined in the Spring framework?

A

Spring Beans are typically defined using XML-based configuration, Java annotations, or through Java-based configuration classes, specifying their properties, dependencies, and behaviors.

21
Q

How does the Spring IoC container manage dependencies between Spring Beans?

A

The Spring IoC container handles dependency injection, resolving and injecting dependencies into Spring Beans, promoting loose coupling and modularity.

22
Q

Where are Spring Bean objects stored in a Spring application?

A

Spring Bean objects are stored in the Spring IoC (Inversion of Control) container, which manages their lifecycle, configurations, and dependencies.

23
Q

What is the role of the Spring IoC container in managing Spring Bean objects?

A

The Spring IoC container stores, creates, configures, and manages Spring Bean objects, handling their instantiation, lifecycle, and providing them when requested by the application.

24
Q

What are the two types of Spring IoC containers?

A

The Spring IoC container comes in two types: the BeanFactory and the ApplicationContext, offering different levels of functionalities and services.

25
Q

What additional features does the ApplicationContext provide over the BeanFactory?

A

The ApplicationContext extends the functionality of the BeanFactory, offering advanced features like internationalization, event propagation, AOP (Aspect-Oriented Programming), resource loading, and more.

26
Q

How does the IoC container retrieve beans from memory?

A

The IoC container maintains metadata and references to bean definitions in memory, enabling it to retrieve, instantiate, and manage beans based on their configurations when requested by the application.

27
Q

What impact does the IoC container’s memory management have on application performance?

A

Efficient memory management by the IoC container contributes to optimized application performance by controlling memory usage, object creation, and disposal based on bean lifecycle and scope.

28
Q

How does Spring Boot differ from the traditional Spring Framework?

A

Spring Boot is an opinionated and convention-over-configuration framework that simplifies the setup and configuration of Spring-based applications, whereas the traditional Spring Framework requires more manual configuration.

29
Q

What does Spring Boot provide out-of-the-box?

A

Spring Boot provides a set of preconfigured defaults, auto-configuration, embedded servers, production-ready features, and starter dependencies, reducing the need for manual configuration.

30
Q

How does Spring Boot handle configuration?

A

Spring Boot uses sensible defaults and auto-configuration, reducing the need for explicit configuration files, annotations, and boilerplate code often required in the traditional Spring Framework.

31
Q

What is the role of Spring Boot starters?

A

Spring Boot starters are dependency descriptors that simplify the inclusion of various modules, reducing the need for explicit dependency management in the traditional Spring Framework.

32
Q

What benefits does Spring Boot offer in development?

A

Spring Boot simplifies and accelerates the development process by providing a streamlined setup, reducing configuration efforts, and enabling rapid prototyping and development of applications.