Spring Interview Qs Flashcards

1
Q

What is a POJO?

A

Plain Old Java Object

Not bound by any special restriction and not requiring any class path.

A POJO is a Java object that is bound to no specific framework, unlike a JavaBean is a special type of POJO with a strict set of conventions.

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

What is a software framework?

A

a universal, reusable software environment that provides particular functionality as part of a larger software platform to facilitate development of software applications, products, and solutions

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

What is a “bean”?

A

classes that encapsulate many objects into a single object (the bean)…

A bean is an object that is instantiated, assembled, and otherwise managed by a Spring IoC container.

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

What is REST?

A

REpresentational State Transfer

A software architectural style that defines a set of constraints to be used for creating web services.

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

Why use Springboot?

A

Lightweight and modular; IoC container contains and maintains life cycle and configuration of application objects; helps create MVC; handles JDBC exceptions; loose coupling
Less boilerplate code
Springboot makes it easy to create Java enterprise applications

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

What does it mean for a system to be “loosely coupled”?

A

a loosely coupled system is one in which each of its components has, or makes use of, little or no knowledge of the definitions of other separate components. keeps disparate parts independent, flexible, and modular.

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

What is the Spring IoC Container?

A

IoC: Inversion of Control. Object gives its dependences instead of creating or looking for dependent objects; provides consistent means of configuring and managing Java objects using reflection. Can also be considered “dependency injection container”

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

What is Dependency Injection?

A

A software design concept that allows a service to be used/injected in a way that is completely independent from client consumption. This prevents the client from modifying when the underlying service changes.

It separates the creation of a client’s dependencies from the client’s behavior, which allows program designs to be loosely coupled

Design pattern in Spring that allows loose coupling, helps with single responsibility, deals with the way objects fulfill their dependent objects.

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

What are the different types of DI?

A

Constructor-Based: best for required dependencies

Setter-Based: best for optional dependencies (not injected until called)

Field-Based

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

What is CORS?

A

Cross-Origin Resource Sharing (CORS) is a header based mechanism that allows a server to indicate any other origins than its own from which a browser should permit the loading of resources.

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

What does it mean that Spring Boot is “opinionated”?

A

Spring Boot has intelligent auto-configurations that favor convention and are designed to get you up and running as quickly as possible.

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

Where do you change the default settings for your Spring project?

A

application.properties

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

@Entity

A

Marks a class to have its fields mapped (as a row) to the columns of a table, in a database.

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

@GeneratedValue

A

A value which is generated based on the specified strategy. Defaults to auto.

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

@ID

A

Marks the primary key of an Entity.

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

@Transient

A

Used to indicate that a field is not to be persisted in the database.* (password)

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

@Component

A

@Component annotation means that only a single instance of the annotated class gets created. Also in most cases this instance is automatically created on application startup, perhaps when some other common Spring annotations are used.

18
Q

@Controller

A

Includes buisness logic that handles requests and controls the flow of data.

19
Q

@Autowired

A

Fetches the bean from the IOC container and inject it into the scope.

20
Q

3 Types of @Autowired

A
By Type (field method of DI)
Constructor
By Name (setter method of DI)
21
Q

@RequestMapping

A

The annotation is used to map web requests to Spring Controller methods. Can define which kind of request is being used.*

22
Q

@SpringBootApplication

A

Scans project for spring componenents and autowires libraries using auto configuration. @Configuration is the first priority loaded by SpringBootApplication
Also performs @ComponentScan, @EnableAutoConfiguration

23
Q

@Configuration

A

Spring @Configuration annotation is part of the spring core framework. Spring Configuration annotation indicates that the class has @Bean definition methods. So Spring container can process the class and generate Spring Beans to be used in the application.

24
Q

@ResponseBody

A

The @ResponseBody annotation tells a controller that the object returned is automatically serialized into JSON and passed back into the HttpResponse object.

25
Q

@RestController

A

The @RestController annotation was introduced in Spring 4.0 to simplify the creation of RESTful web services. It’s a convenience annotation that combines @Controller and @ResponseBody – which eliminates the need to annotate every request handling method of the controller class with the @ResponseBody annotation.

26
Q

@Bean

A

Spring @Bean Annotation is applied on a method to specify that it returns a bean to be managed by Spring context. Spring Bean annotation is usually declared in Configuration classes methods. In this case, bean methods may reference other @Bean methods in the same class by calling them directly.

27
Q

@EnableAutoConfiguration

A

Annotation that enables Spring Boot to auto-configure the application context. It automatically creates and registers beans based on both included jar files in the classpath and the beans defined by us.

28
Q

@SpringBootApplication

A

@EnableAutoConfiguration: enable Spring Boot’s auto-configuration mechanism
@ComponentScan: enable @Component scan on the package where the application is located
@Configuration: allow to register extra beans in the context or import additional configuration classes on startup

29
Q

SpringApplication.run();

A
  1. ) Starts Spring
  2. ) creates Spring context
  3. ) applies annotations
  4. ) sets up container
30
Q

Six Key Areas of Spring Framework:

A
Aspect-Oriented Programming (AOP)
Core
Data Access
Integration
Testing
Web
31
Q

Spring Framework - Core

A

handles dependency injection (the IoC containter)… creates and maintains objects and their dependencies… the “glue” of the application

32
Q

Spring Framework - Web

A

The Spring Web MVC framework provides Model-View-Controller (MVC) architecture and ready components that can be used to develop flexible and loosely coupled web applications. The MVC pattern results in separating the different aspects of the application (input logic, business logic, and UI logic), while providing a loose coupling between these elements.

The Model encapsulates the application data and in general they will consist of POJO.

The View is responsible for rendering the model data and in general it generates HTML output that the client’s browser can interpret.

The Controller is responsible for processing user requests and building an appropriate model and passes it to the view for rendering.

33
Q

Aspect-Oriented Programming (AOP)

A

In computing, aspect-oriented programming is a programming paradigm that aims to increase modularity by allowing the separation of cross-cutting concerns.

Aspect-Oriented Programming entails breaking down program logic into distinct parts called ‘so-called concerns’. The functions that span multiple points of an application are called cross-cutting concerns and these cross-cutting concerns are conceptually separate from the application’s business logic. There are various common good examples of aspects like logging, auditing, declarative transactions, security, caching, etc.

The key unit of modularity in OOP is the class, whereas in AOP the unit of modularity is the aspect. An aspect is a common feature that is spread across methods, classes, object hierarchies, or even entire object models. Dependency Injection helps you decouple your application objects from each other and AOP helps you decouple cross-cutting concerns from the objects that they affect.

Spring AOP module provides interceptors to intercept an application. For example, when a method is executed, you can add extra functionality before or after the method execution.

34
Q

Data Access

A

Extending a DAO interface in the JPA specific Repository interface - JPARepository - enables Spring Data to find this interface and automatically creates an implementation for it.

This reduces boilerplate code for data access and database transactions (@Transactional means that all actions must happen or none at all, like moving data from one table or account to another… data may be duplicated or lost if one part fails)

Handles exceptions from different databases and gives common definitions

Makes testing easier… helps create embedded test database for testing

35
Q

Integration

A

Making different systems/applications work together

Spring makes it easy to expose and invoke web services (like REST)

RestTemplate abstracts away tedious details: connecting, sending command, handling response

36
Q

@Repository

A

a Spring annotation that indicates that the decorated class is a repository. A repository is a mechanism for encapsulating storage, retrieval, and search behavior which emulates a collection of objects.

37
Q

What does it mean that an API is RESTful?

A

(also referred to as a RESTful web service or REST API)

based on representational state transfer (REST), which is an architectural style and approach to communications often used in web services development

RESTful API is an architectural style for an application program interface (API) that uses HTTP requests to access and use data. That data can be used to GET, PUT, POST and DELETE data types

REST is generally preferred over other similar technologies, bc it uses less bandwidth, making it more efficient for internet usage

38
Q

What is the difference between JPA and Hibernate?

A

Hibernate is a JPA Provider

interface analogy:
if JPA is an interface, then Hibernate represents a class that implements the interface
39
Q

What are the differences between SOAP and REST APIs?

A

SOAP stands for Simple Object Access protocol and REST stands for Representational State Transfer.

SOAP is a protocol and REST is an architectural pattern.

SOAP is resource intensive.

SOAP cannot make use of REST but REST can make use of SOAP.

SOAP only works with XML formats whereas REST works with plain text, XML, HTML and JSON.

SOAP is ACID compliant right out of the box, you would use this protocol when you are concerned about security for your DB. SOAP is used to sensitive information in enterprise architecture.

40
Q

How does Spring Boot differ from Spring framework?

A

Spring Boot is opinionated. It takes an opinionated view of the Spring framework, auto configs are based on the most common use cases of Spring. For example, Spring Boot comes with Tom Cat already configured. Different starters guide the auto-configs. Right out of the box, it auto configs more than Spring does. Session factory and IoC comes right out of the box but needs to be configured with Spring.