Saturday, May 27, 2023

Aggregator Design Pattern In Java Microservices with Examples

The Aggregator design pattern in Microservice architecture is a design pattern used to compose a complex service by aggregating the responses of multiple independent microservices. It's also one of the essential Microservices Design patterns along with SAGA, CQRS, and Event Sourcing. This pattern is proper when a client request requires data or functionality distributed across multiple microservices. It can improve the performance and scalability of the system by allowing each microservice to focus on a specific task and reducing the workload of a single microservice. In this article, we will discuss how the Aggregator Microservice Pattern can be implemented in Java using various approaches, such as asynchronous communication, synchronous communication, or a combination of both. We will also provide examples of code to illustrate each approach.

What is Circuit Breaker Design Pattern in Microservices? How to implement it?

Hello guys, Microservices design patterns are very important concepts for Java developers to learn, not just to create a robust, scalable, and high-performance Microservice architecture but also to do well on Java developer interviews. In the past, I have shared several Microservices design patterns like e Event Sourcing, SAGA, Database Per Microservices, CQRSAPI Gateway, and also shared best practices to design Microservices and in this article, I am going to talk about Circuit-Breaker Design Pattern, and how you can implement in Java using Spring Cloud Framework.  This is not just an important Microservice Pattern but also a popular Microservice question which I have also mentioned earlier in my article about 15 Microservices questions for Interviews. If you haven't read that article yet, I suggest read it, especially if you are preparing for Java and Microservice interviews. 

Friday, May 26, 2023

How to find Kth Smallest Element in a Binary Search Tree? [Solved]

Hello guys, I have been sharing binary search tree-based coding interview questions for quite some time. In the last article, we looked at how to find the maximum sum level in a given binary tree, and in this article, we will find the kth smallest number in a given binary tree like the 5th smallest or 3rd smallest number. Before we find the kth smallest in a Binary search tree, We need to understand the binary search tree. A Binary tree is a data structure in which each node can have at most two children. That is, each node in the binary tree will have data, left child and right child. The first node of the tree is called the Root.

How to find the maximum sum level in binary tree in Java? Example Tutorial

Hello guys, if you are preparing for a coding interview and wondering how to find the maximum sum level in a given binary tree in Java then you have come to the right place. I have been sharing binary tree coding problems for the last few months and in the past, we have seen questions like finding kth smallest element and finding the lowest common ancestor of a binary tree in Java in this article, you will learn how to find the maximum sum level in a given binary tree of integers or numbers. But, before finding the maximum sum level of a binary tree in java, we need to have a good understanding of a binary search tree. Both theoretical knowledge and how to implement binary search tree in Java is important to solve tree-based coding problems

Thursday, May 25, 2023

Difference between application.properties vs Application.json vs Application.yml in Spring Boot

Hello guys, if you have worked in any Spring Boot application then you may have noticed that there are multiple ways to declare configuration for Spring Boot application. I am sure you must have noticed application.propties, application.json, and application.yml while working in proprietary or open source Spring Boot application. When I first started, it was application.propties and it was quite familiar because I have used properties file in past for specify configuration of Java application but when I first see applcation.json and application.yml I was bit confused like what they are and does they really work? In the end I found out that they are just different ways to specify configuration for any Spring Boot application. 

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.

Wednesday, May 24, 2023

10 Examples of RestTemplate in Spring Framework

Hello guys, if you are wondering how to send GET and POST request to your API or Web Service from a Java based Spring Framework then you would be glad to know that You can use use RestTemplate class from Spring Framework. It's a fully functional HTTP client which is really really useful in this age of API. I have used RestTemplate to consume JSON from API before as well as sending different kind of request like POST, PUT, DELETE and PATCH to any REST API. For example, in this article, I shared how to send POST request using RestTemplate and how to set header on HTTP request using RestTemplate. Yes, RestTemplate also allow you to send headers like Authorization on Http Request. 

How to Handle REST exception in Spring Boot Application? Example Tutorial

Hello everyone, in this article we are going to take a look at how to handle REST API exceptions in Spring Boot. It is crucial to handle errors correctly in APIs by displaying meaningful messages as it helps API clients to address problems easily. What happens if we don’t handle the errors manually? By default, the spring application throws a stack trace, which is difficult to understand. Stack traces are mainly for developers hence it is useless for API clients. That's why its very important to use proper HTTP code and error messages to convey errors and exception to client and also logging so that support team can better handle them. Ideally you should tell what went wrong and how to fix it? For example, if the error is due to duplicate data then clearly say, already existed, try with a new one. Similarly, if authentication fail then clearly say authentication failed instead of throwing some other exception. 

Tuesday, May 23, 2023

Difference between VARCHAR and CHAR data type in SQL Server? [Explained]

Hello all, today, I am going to share an interesting SQL Server interview question, which will not only help you in your interview but also in your day-to-day work. It explains one of the critical concepts of SQL Server, the difference between VARCHAR and CHAR data type. I am sure, you all have used both of them numerous times but because it's so common many of us ignore the difference between them and when asked to choose between VARCHAR and CHAR on interviews, they fail to give a convincing reason. The difference is not just significant from an interview point of view but also from a robust database design because an incorrect choice of data type not only limit what kind of data you can put on but also waste precious space and makes your query slower, particularly when you have to deal with the massive amount of data.

How Long It Take To Become a DBA (Database Administrator) in 2024? 7 days, 1 month or 1 year?

Hello guys, if you want to become a Database Administrator in 2024 and wondering how long does it take to learn SQL and Database and become a professional Database Administrator or Junior DBA then you are at right place. In the past, I have shared free SQL and Database courses as well roadmap to become a Web Developer and in this article, I am going to share how long it will take you to become a DBA in 2024. Along the way, I will share best way to learn SQL and Database and what is the best way to become a DBA quickly. So continue reading and find out what it takes to become a DBA and get a job in real world. I will also share all the skills you need to become a DBA in 2024.

What is window function in SQL with Examples? How and when to use them?

Hello folks, if you are wondering what is window function and what problem does it solve then you have to the right place. In this article, I would be explaining the windows functions with examples, how it works, and when you need to use it. Firstly what is a Window Function in SQL? A window function performs a calculation across a set of table rows that are similarly related to the current row. The current row is the row in which function evaluation occurs. This is comparable to the type of calculation that can be done with an aggregate function. But unlike regular aggregate functions like sum, avg, max, and min, that perform operations on an entire table.

Monday, May 22, 2023

How to set base URL for REST in Spring Boot? Example Tutorial

Hello guys, if you are wondering how to set base URL for REST API in Spring Boot then you have come to the right place. Earlier, I have shared best REST API Courses for Java developers, REST API Books,  and a complete guide to create RESTful Web service using Spring Boot, in this article, I will show you how to set a base URL in any spring boot application? If you don't know what is a base URL in a REST application or website, let me give you a brief overview first.  A base URL is the continuous element of your REST API or website's address. For example, you'll notice that the address portion http://twitter.com displays in the address bar whenever you log on to your Twitter account or visit a Twitter profile from your computer. This is the primary or base URL.

How to Enable Disable Spring Security in Spring Boot? Example Tutorial

Hello guys, if you are wondering how to enable and disable Spring Security in a Spring Boot based Java application then you have come to the right place. In the past, I have shared best Spring security courses25 Spring Security questions, as well multiple Spring security tutorials like how to use HTTP Basic auth in Spring Security etc.  and in this article, I will share multiple ways to enable and disable Spring Security in a Spring boot application. But, before that, if you are new to Spring Security then find out what is Spring Security and how does it work?  At its core, Spring Security is simply a bunch of servlet filters that assist you with adding authentication and authorization to your web application. 

Sunday, May 21, 2023

Top 5 Spring Boot 3 Features for Java Developers

Hello guys, if you want to learn Spring Boot 3 and wondering which features to start with then you have come to the right place. Earlier, I have shared 5 worth learning features from Spring Framework 6 and in this article, I am going to share 5 Spring Boot 3 features which are worth knowing and learning for every Java developer But, before we get to the best 5 features that you definitely need to check out in Spring Boot 3, let me tell you a bit about what Spring really is. Spring is basically a framework that can be used for developing various types of applications with the help of Java platforms. It also provides support for the Plain Old Java Objects, also known as POJOs, that developers can use for easily creating the Java SE Programming Model with full and partial Java EE.

How to do Integration Testing in Spring Framework? @SpringBootTest Example Java

Hello guys, if you are wondering how to test your Spring Boot application then you have come to the right place. Earlier, I have shared popular Spring Boot Testing Interview Questions and Spring Security Interview Questions and In this article, I will show you examples to test your Spring Boot application using @SpringBootTest annotation, which allows you to write Integration tests. When I talk about spring boot integration testing, I am talking about launching an application in ApplicationContext and performing tests. For integration testing, Spring Framework has a specific test module. It's referred to as a spring test. If we're going to utilize spring-boot, we'll need to use spring-boot-starter-test, which uses spring-test and other dependencies inside.

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.

Saturday, May 20, 2023

How to upload a file and JSON data in Postman? Example Tutorial

How to upload a file and JSON data in Postman is a common question when you are dealing with REST APIs. In order to do this, you need to send through POST request. So in this article, we are going to explain this using different examples where you can upload a single file in different ways. upload a list of files, upload as an object or upload a list of objects containing images from postman. So before moving to the following different aspects of uploading a single file in different ways, let's assume that in your postman, you are using header named "Content-Type" with the value of "multipart/form-data".

Spring Boot Backend + Vuejs Example [Java tutorial] - Part 1

In this tutorial, we will show you the Vue.js HTTP client and Spring Boot Server example that uses Spring JPA to do the CRUD with the H2 database and Vue.js as frontend technology to make requests and receive responses. But before moving to the Spring Boot and VueJs Example, Let's discuss what is Vuejs and its use cases.

Friday, May 19, 2023

Top 5 Spring 6 New Features Java Developer Should Learn

Hello guys, if you are wondering what is New in Spring Framework 6 release and what new feature it has got or what does it support now then you have come to the right place. In this article, I will share 5 key changes from Spring Framework 6 which are worth knowing for Every Java developer. Before we get to the top 5 features of Spring that you need to definitely learn, let me tell you a bit more about what Spring Framework really is. Spring is basically a framework that can be used for developing various types of applications with the help of Java platforms. It also provides support for the Plain Old Java Objects, also known as POJOs, that developers can use for easily creating the Java SE Programming Model with full and partial Java EE.

What is API Gateway Design Pattern in Microservices? With Examples

Hello guys, API Gateway Design Pattern is a pattern that has emerged as a popular solution for managing APIs in a microservices architecture. As the number of services in the architecture increases, it becomes challenging to manage the APIs and handle requests from external clients. To address this challenge, API Gateway Design Pattern provides a single entry point for all the APIs in a microservices architecture. In the past, I have shared several Microservices design patterns like e Event Sourcing, SAGA, Database Per Microservices, CQRS, API Gateway, and also shared best practices to design Microservices and in this article, I am going to talk about the API Gateway Design Pattern, and how you can implement in Java using Spring Cloud Framework (Spring Cloud Gateway). 

Thursday, May 18, 2023

Java + Spring Boot + Microservices Example - Step by Step Guide

Hello guys, if you are wondering how to create a Microservice in Java and Spring Boot then you are at the right place. In the past, I have shared best Spring Boot courses for Microservices, Interview Questions as well as essential Microservice design principles and patterns like API Gateway, Circuit breaker, CQRS, Event sourcing etc and In this article, we will cover the fundamentals of microservices with Spring Boot utilizing Spring cloud. We will cover a few fundamental ideas and then we will make a little microservices to give you an outline. I will also share step by step guide to make Microservices in Java and then deploy them using Docker and Kubernetes on Cloud. 

Monday, May 15, 2023

Asynchronous Messaging In Java? JMS, Kafka, and RabbitMQ Examples Tutorials

Hello fellow Java developers? Are you tired of those pesky synchronous messages clogging up your code like old grease in a drainpipe? Fear not, because today we're talking about asynchronous messaging in Java – the ultimate solution for decoupling your processes and improving the performance of your applications.  But before we dive into the juicy details, let's start with the basics. What is Asynchronous Messaging? Asynchronous messaging is a method of communication between two or more processes like Microservices, where the sender sends a message and doesn't wait for a response before continuing with its own tasks. This is in contrast to synchronous messaging, where the sender must wait for a response before continuing.

What is CQRS Pattern in Java Microservices? Command Query Responsibility Segregation Example Tutorial

Hello guys, if you are wondering what is CQRS pattern and when and how to use it in your Microservices then you have come to the right place. CQRS is one of the 10 essential Microservice pattern and can be used when your application is either read heavy or write heavy and reading and writing requirement are very different. It aims to separate your app into two parts, command part which writes data and query part which read data and that's how it allows you to develop, scale and optimize them separately. It's also one of the popular Microservices Questions and if you are preparing for interviews, you should prepare this pattern as well. Earlier, I have explained SAGA Pattern and Database Per Microservice pattern and in this article I will explain CQRS pattern, when to use it and what problem does it solve. 

Sunday, May 14, 2023

How To Implement Security in Microservices Architecture

Hello guys, if you are wondering how to secure your Microservices, like put authentication and authorization then you have come to the right place. Security is a critical aspect of any software architecture, and microservices architecture is no exception. With its distributed and decentralized nature, microservices architecture presents unique security challenges that must be addressed to ensure the integrity, confidentiality, and availability of the system.In this article, we will discuss some best practices for implementing security in microservices architecture.

Saturday, May 13, 2023

SAGA Design Pattern In Java Microservices with Example

Hello guys, if you want to learn about SAGA Microservice design pattern then you have come to the right place. SAGA is one of the 10 essential Microservice Design Patterns I have shared earlier and it solve a critical problem related to distributed transaction. But, before we get to the different examples that will teach you all about SAGA microservice design patterns in Java, let me tell you a bit more about what it really is. A microservice-based application is basically a distributed system. The overall system consists of multiple minor services, which provide the overall application functionality. This architectural style offers numerous benefits as well as several limitations. SAGA Pattern is also one of the popular Microservice interview question and if you are going for interview, it make sense to learn and understand this design pattern in depth. 

Friday, May 12, 2023

What is Event Sourcing Design Pattern in Java Microservices? Example

Hello Java programmers, if you are tired of constantly trying to keep track of your application's current state using a traditional relational database then the Event Sourcing pattern might be just what you need. Event Sourcing is a popular pattern in Microservice architecture that allows services to persist and query the state of an application using a sequence of events instead of storing the current state. This pattern has gained popularity because it helps to build complex systems with a clear audit trail and support for long-term scalability. By storing a sequence of events, rather than just the latest state, developers can reconstruct the application state at any point in time, even after failures or bugs. It's also one of the 10 essential Microservice patterns I have shared earlier and it's one of the top 3 along with Saga and CQRS patterns which we have seen in my earlier articles.