Difference between @Component, @Controller, @Service, and @Repository in Spring

Hello guys if you are wondering what is the difference between @Component, @Controller@Service, and @Reposistory annotation in Spring Framework then you have come to the right place. In the past, I have shared 15 Spring Boot Interview Questions and 30 Spring MVC questions and in this article, I am going to answer the fundamental and popular Spring questions about @Component, @Controller@Service, and @Repository annotation, but before we go into differences, let's understand the similarity first.

Difference between @PreAuthorized and @RolesAllowed Annotations in Java (with Example)

Hello guys, In Java programming and backend application development security plays a pivotal role in safeguarding applications from unauthorized access and malicious activities. To ensure proper control over access rights, Java developers often utilize annotations, such as @PreAuthorized and @RolesAllowed of Spring Security framework. Earlier, I have shared how to setup Spring Security and talked about HTTP Basic Authentication and In this article, we will explore the functionality of both annotations, their differences, and use real-world and programming examples to illustrate their significance.

Difference between @GetMapping @PostMapping @PutMapping @DeleteMapping @PatchMapping

In the world of web development, the Spring Framework is widely known for its versatility and ease of use. It provides several annotations that simplify the process of handling HTTP requests and mapping them to specific methods in Spring controllers. Among these annotations, @GetMapping, @PostMapping, @PutMapping, @DeleteMapping, and @PatchMapping are some of the most commonly used ones. In this article, we will explore each of these annotations in detail, highlighting their purposes, differences, and providing examples to better understand their usage.

13 Spring Boot Actuator Interview Questions Answers for 5 Years Experienced

If you have used Spring Boot, you may know that Spring Boot is all about convenience, and the Spring Boot actuator is one of such features that provides a convenient way to interact with your app using HTTP and JMX. It's also essential from the Spring Boot interview point of view. While I did include some Spring Boot Actuator questions in my earlier post about frequently sked Spring boot interview questions, many of you asked for more questions to cover Spring Boot Actuator in depth, so I decided to write a separate article. In this article, we will see some popular Spring boot Actuator interview questions and, along the way, learn more about this helpful Spring boot Feature

Difference between JpaREpository, CrudREpository, and PagingAndSortingRepository

Hello and welcome to my blog post. In this article, we will delve into the world of Spring Data repositories and explore the key differences between three commonly used interfaces: JpaRepository, CrudRepository, and PagingAndSortingRepository. If you're a Spring Boot developer working with databases, understanding the distinctions between these interfaces is crucial for efficient data management. So let's dive right in and uncover the unique features and use cases of each repository interface.

Difference between @AutoWired and @Qualifier in Spring Framework?

Hello guys, if you are preparing for Spring Framework or Spring Boot interviews then you should always prepare comparison questions like what is difference between @Qualifier and @AutoWired annotation in Spring? This kind of questions are good to demonstrate not only your knowledge but also how well you understand them and its also your chance to impress the interviewer. In the past, I have answered @Bean vs @Component and @Controller vs @RestController annotation and in this article, I am going to explain you the difference between @Autowired and @Qualifier in Spring Framework. 

What is @Conditional annotation in Spring Framework? Example Tutorial

Hello guys, if you want to know what is @Conditional annotation in Spring Framework and Spring Boot, and how to use it then you have come to the right place. Earlier, I have shared best free courses to learn Spring Framework and Spring Boot, and in this article, you'll learn what they are, how to use them with practical examples. Spring 4.0 introduced the @Conditional annotation that is used for conditional checking for bean registration. This annotation offers more support than the @Profile annotation provided by the spring framework and most of the Spring Boot matching is attributed to this annotation. It allows you to setup features based upon certain conditions like presence of a class in classparth or a JAR File which is how Spring Boot Auto-configuration works.

Difference between @Controller vs @RestController in Spring Framework

Hello and welcome to the blog post. If you are preparing for Java or Spring Boot interview, you may have come across this topic. In this article, we are going to have a look at the difference between @Controller and @RestController annotation. Let's understand with the help of an example.
Spring Framework is a popular open-source application framework that provides infrastructure support for developing Java applications. One of the essential components of Spring Framework is the controller, which is used to handle HTTP requests and provide responses to clients. In Spring, there are two types of controllers: @Controller and @RestController.

Difference between @RequestParam and @PathVariable in Spring MVC

Hello guys, if you are wondering what is difference between @ReqestParam and @PathVaraible annotation in Spring MVC, most likely because it was asked to you on a Java and Spring interview or maybe you are just curious then you have come to the right place. In the past, I have talked about difference between @Component, @Service, @Reposistory and @Controller annotations and in this comprehensive article we are going to take an in-depth look at the difference between the two most frequently used annotations in Spring MVC. It provides two commonly used annotations, namely @RequestParam and @PathVariable, which play a significant role in parameter handling within web applications. 

Differences between OAuth 2.0 and JWT (JSON Web Token)

Hello guys, both OAuth 2.0 and JWT (JSON Web Tokens) are two widely used authentication and authorization protocols in modern web applications. While both serve similar purposes, there are some key differences between the two that are important to understand, which we will see in this article. This is also an important interview question and if you are preparing for Java and Microservices developer interviews, it's better to know how this two technology works and what are the key differences between then.  In short, OAuth 2.0 is primarily used for authorization, whereas JWT is primarily used for authentication. OAuth 2.0 uses access tokens, whereas JWT is a self-contained token. OAuth 2.0 has a complex authorization flow, whereas JWT has a simple flow. OAuth 2.0 provides better security as it reduces the risk of unauthorized access to protected resources, while JWT can be intercepted if not properly secured. OAuth 2.0 access tokens are short-lived and need to be refreshed periodically, whereas JWTs do not expire.

Difference between @RequestParam vs @RequestBody in Spring MVC? (with Example)

Hello everyone, in this article, we are going to look at an interesting topic from the Java Spring framework and the topic is, to find the difference between @RequestBody and @RequestParam. If you don't know this is one of the frequently asked Spring MVC interview question and also two of the most used annotation when creating backend of a Java web application in Spring Framework. Earlier, I have explained difference between @RequestBody and @ResponseBody in Spring MVC and REST APIs, and in this article, I am going to tell you the difference between @RequestBody and @RequestParam annotation in Spring Framework. It is worth noting that these two annotations are frequently used in Spring Boot REST API.

Difference between Spring Boot vs Spring Cloud in Java

Hello guys, if you are wondering, what is difference between Spring Boot and Spring Cloud then you re not alone. Many Java developer are not familiar with various spring boot projects like Spring Security, Spring Data JPA, Spring Batch, Spring Boot, Spring Cloud etc and this lack of knowledge prevent them from taking full advantage of Spring Framework.  In last article, I have explained difference between Spring framework and Spring Boot and in this article we are going to discuss the difference between Spring Boot and Spring Cloud. Before we dive into the difference between the two terms. Let us take a look at different terms like Spring, Spring Boot, and Spring Cloud.

5 Essential Spring Boot Annotations with Examples in Java - Tutorial

Hello guys, if you are coding in Java for long then you know that Annotations have completely changed the way you write Java code. It's now impossible to write any Java code without using annotations but that's for good. They provide a lot of value and that's why it's important for a Java developer to get familiar with essential annotations of the framework he or she is using. When I think about Java, some of the essential annotations which come to our mind are @Override, @SuppressWarning, and @Deprecated. Similarly, if you are using the Spring Boot framework, an extension of the Spring framework which aims to simplify the Java development with Spring, you will often end up using a couple of annotations like @SpringBootApplication or @EnableAutoConfiguration.

Difference between Mockito.mock(), @Mock and @MockBean annotation in Spring Boot

Hello guys, if you are wondering what is the difference between Mockito.mock(), @Mock and @MockBean annotation in Spring Boot then you have come to the right place. In the Spring Boot framework, @Mock and @MockBean are both annotations used for creating mock objects in unit testing scenarios. However, they are used in different contexts and have some differences in their behavior which you will find in this article. In the past, I have shared difference between @Controller and @Service as well @RequestParam vs @PathVariable and in this article, I will explain the difference between @Mock and @MockBean annotations in Spring Boot. To be honest, I love this kind of questions as it not only help on interviews but also help to learn the concept better and you should also love them too.

What is @Component annotation in Spring? What does it do?

Hello guys, One of the main reason many people use Spring Framework is Dependency injection and auto-wiring, which means you don't need to write code to create and inject dependency, Spring will do it for you. But does it do it and how @Component annotation helps? Well, In Spring, the @Component annotation is used to mark a class as a Spring bean that should be managed by Spring's Inversion of Control (IoC) container. When a class is annotated with @Component, Spring automatically scans for such components during application startup and creates instances of these components that can be used for dependency injection. The @Component annotation is the foundation for other stereotype annotations in Spring, such as @Service, @Repository, and @Controller, which are specializations of @Component. These annotations are used to further specify the role and purpose of a component in a Spring application.

What is ContextLoaderListener in Spring MVC? Example Tutorial

The ContextLoaderListner is one of the essential components of the Spring MVC framework, probably the most important after the DispatcherServlet itself. It is used to create the root context and responsible for loading beans, which are shared by multiple DispatcherServlet like beans related to the service layer and data access layer. In general, When you develop Spring MVC based web applications and also using Spring in the services layer, you need to provide two application-contexts. The first one is configured using ContextLoaderListener, and the other is set using DispatcherServlet. The DispatcherServlet is responsible for loading web component-specific beans like controllers, view resolvers, and handler mappings while, as I said before, ContextLoaderListener is accountable for loading middle-tier and data-tier beans which forms the back end of Spring applications.

What is @PropertySource Annotation in Java and Spring? PropertySource Example Spring Boot

Hello Java developers, if you are using Spring Framework or Spring Boot in your new project and wondering what is property source in Spring Framework and how to use @PropertySource annotation then you have come to the right place. Earlier, I have shared the best books and online courses to learn Spring Framework and in this article, I will teach you how to use @PropertySource annotation in Spring to read Environment variables and inject properties using @Value annotation. In the Spring application, one of the files that are needed to provide properties to the Spring environment is the @Configuration classes. 

How @Configuration, @Component, and @ComponentScan annotations works in Spring Framework? Component Scanning Example

Hello guys, if you are wondering how to does autowiring work in Spring Framework and how does Spring Framework find dependency in runtime then you have come to the right place. Earlier, I have explained How Spring MVC works and how Spring Security works, and In this tutorial, I will tell you how component scanning and auto-wiring works in Spring. You will also learn how to enable component scanning in a Spring application. When you develop a software application using spring, you need to tell the Spring framework where to look for Spring components. Using component scanning it is very much easier as this enables auto-detection of beans by spring container and smoothly.

How does HTTP Request is handled in Spring MVC? DispatcherServlet Example Tutorial

One of the common interview questions in Spring MVC is, how does the DispatcherServlet process a request in Spring MVC? or What is the role of DispatcherServlet in the Spring MVC framework? This is an excellent question for any Java or Spring web developer because it exposed the candidate's knowledge about Spring MVC architecture and how its main components like Model, View, and Controller.   The answers to this question show how much you know about the Spring MVC framework and its working. 

What is the use of DispatcherServlet in Spring MVC? Interview Question Example

Hello guys, In today's article we are going to discuss one interesting and the important Spring MVC concept, which is also a popular Spring Interview question. How DispatcherServlet works internally in Spring MVC or What is the role of DispatcherServlet in Spring MVC are some of the frequently asked Spring MVC Interview Questions. You might have seen them already during your previous Java web development interviews but if you have not, it's a good question to know. In this article, I'll answer these questions by explaining What is DispatcherServlet and its importance in Spring MVC. The DispatcherServlet is one of the important components of the Spring MVC web framework and acts as a Front Controller.