What is Java?
What is Spring Boot?
What are Annotations in Java?
What are the OOPS (Object-Oriented Programming) concepts?
What is Multithreading?
What are Spring Boot concepts?
What is
@SpringBootApplication
?What is the difference between
@RestController
and@Controller
?What are CRUD operations and the corresponding HTTP methods used?
What are HTTP Headers and HTTP Status Codes?
What is the purpose of
@Configuration
,@CrossOrigin
, and@ControllerAdvice
?What are Spring Core annotations (
@Bean
,@Component
,@ComponentScan
,Scope
)?What is the difference between
JPARepository
andCrudRepository
?What is the difference between
MongoTemplate
andMongoRepository
?What is
@Valid
used for in Spring Boot?What is
CommandLineRunner
?
What is Spring Boot Actuator and its purpose?
What is Spring Security?
What is
ResponseEntity
and its purpose in Spring Boot?What are the advantages of Microservice architecture?
What is the purpose of Zuul/Spring Cloud Gateway and Eureka Service Registry?
How do Microservices interact with each other?
What is
RestTemplate
?What is
ResponseEntity
used for in microservices communication?
- List a few Spring Boot Starters.
What is Java?
Java is a high-level, object-oriented programming language that was developed by Sun Microsystems (now owned by Oracle) in the mid-1990s. It is platform-independent, meaning that once a Java program is written, it can run on any system that has a Java Virtual Machine (JVM). Java is widely used for building large-scale applications, mobile apps (Android), web services, and enterprise solutions.
Key features of Java include:
Object-Oriented: Encourages the use of objects to organize code.
Platform-Independent: Write once, run anywhere.
Robust: Exception handling and memory management to avoid crashes.
Multi-threaded: Supports concurrent programming.
Secure: Built-in security features.
What is Spring Boot?
Spring Boot is a framework built on top of the Spring Framework that simplifies the process of setting up and deploying Spring-based applications. It eliminates the need for boilerplate code and configuration, providing defaults for most common configurations. Spring Boot is often used to build microservices, web applications, and RESTful APIs.
Key features:
Auto Configuration: Automatically configures your application based on dependencies.
Embedded Servers: Includes embedded servers like Tomcat, Jetty, or Undertow, eliminating the need for external application servers.
Production-Ready: Includes tools like Actuator to monitor and manage the application.
Microservices Support: Ideal for building microservices architectures.
Annotations in Java
Annotations in Java are metadata that provide data about the program but do not directly affect the program's execution. They are often used in frameworks like Spring, Hibernate, and Java EE to provide configuration and behavior details.
Some common annotations include:
@Override: Indicates that a method overrides a method in the superclass.
@Deprecated: Marks a method or class as deprecated.
@SuppressWarnings: Suppresses specific warnings from the compiler.
In the context of Spring Boot, annotations play a crucial role in defining and configuring various aspects of the application.
OOP Concepts (Object-Oriented Programming)
OOP is a programming paradigm based on the concept of objects, which can contain data (attributes) and methods (functions). The four fundamental principles of OOP are:
Encapsulation: The bundling of data and methods that operate on that data into a single unit (class). It also restricts direct access to some of an object's components, which helps protect the integrity of the data.
Inheritance: The mechanism by which one class can inherit the fields and methods of another. This promotes code reusability.
Polymorphism: The ability to take multiple forms. In Java, this can be achieved through method overloading (compile-time) and method overriding (runtime).
Abstraction: The concept of hiding the complex implementation details and showing only the essential features of an object.
What is Multithreading?
Multithreading is a concurrent execution technique in which multiple threads (smaller units of a process) are executed in parallel. Java provides built-in support for multithreading, allowing applications to perform multiple tasks simultaneously, improving performance and responsiveness.
In Java, multithreading is typically achieved by extending the Thread
class or implementing the Runnable
interface. It is commonly used in applications requiring parallel processing, such as web servers or games.
Spring Boot Concepts
@SpringBootApplication: This is a combination of three annotations—
@Configuration
,@EnableAutoConfiguration
, and@ComponentScan
—used to set up a Spring Boot application. It is typically placed on the main class to bootstrap the application.@RestController vs. @Controller:
@RestController: A convenience annotation that combines
@Controller
and@ResponseBody
. It is used to handle RESTful web services and automatically serializes responses to JSON or XML.@Controller: Used for traditional MVC applications, where views (such as JSP or Thymeleaf templates) are returned.
CRUD Operations & HTTP Methods:
Create: POST
Read: GET
Update: PUT/PATCH
Delete: DELETE
HTTP Status Codes:
200 OK (successful GET request)
201 Created (successful POST request)
400 Bad Request (client error)
404 Not Found (resource not found)
500 Internal Server Error (server error)
Spring Core:
@Bean: Used to define beans in a configuration class.
@Component: Marks a class as a Spring component, making it eligible for component scanning.
@ComponentScan: Scans the package for components, configurations, and services.
Scope: Defines the lifecycle and visibility of beans. Common scopes include:
Singleton: One instance for the entire application (default).
Prototype: A new instance every time a bean is requested.
Request, Session, Application: Specific to web applications.
JPARepository vs. CrudRepository:
CrudRepository: Provides CRUD operations without custom queries.
JpaRepository: Extends
CrudRepository
and adds JPA-specific operations, such as pagination and sorting.
MongoTemplate vs. MongoRepository:
MongoTemplate: Provides a more flexible approach to working with MongoDB, allowing custom queries.
MongoRepository: Offers CRUD operations on MongoDB without the need for custom queries.
@Valid: Used for validating the fields of an object in Spring applications.
CommandLineRunner: An interface for running code at the application startup.
Spring Boot Specific Annotations and Concepts
@Configuration: Marks a class as a source of bean definitions for the application context.
@CrossOrigin: Enables Cross-Origin Resource Sharing (CORS) support for REST endpoints, allowing your API to be accessed from different domains.
@ControllerAdvice: Global exception handling and response manipulation for Spring MVC controllers.
Actuator: A set of production-ready features in Spring Boot to monitor and manage your application, including health checks, metrics, and environment properties.
Spring Security: Provides authentication and authorization mechanisms to secure Spring-based applications.
ResponseEntity: A class that represents an HTTP response, including status codes, headers, and body content. It is used to control the entire response structure in Spring controllers.
Microservices and Spring Cloud
Microservices Architecture: A design style where an application is structured as a collection of loosely coupled, independently deployable services. Each service handles a specific business capability and communicates via lightweight protocols (typically HTTP/REST).
Zuul/Spring Cloud Gateway: API Gateway services used for routing requests to different microservices. They provide features like load balancing, authentication, and rate limiting.
Eureka Service Registry: A service registry used for discovering microservices in a distributed system. Microservices register themselves with Eureka, and other services can discover and communicate with them.
Inter-communication between Microservices:
RestTemplate: Used for making HTTP requests to other services.
ResponseEntity: Used for sending HTTP responses from the microservice to the client.
Spring Boot Starters: Pre-configured templates to help developers easily include common functionality in their applications. Examples include:
spring-boot-starter-web
(for web apps)spring-boot-starter-data-jpa
(for JPA integration)spring-boot-starter-security
(for security)