Blog

In the previous blog post, we covered the basics of how to use Keycloak with Spring boot. In this blog post, we will explore Role-based Access Control to Rest API with Keycloak. So let’s get started! Imagine we have a microservice for a Research Journal Management System that can serve users with two types of…

Read More Role-Based Access Control to REST API with Keycloak

In this tutorial, we are going to see how we can throw custom exceptions with a custom payload in a Spring Boot application and deploy it on AWS as a serverless Lambda function. Let us start by creating a simple Spring boot project. In this project, we are going to create a Request Handler that…

Read More Handle Custom JAVA Exceptions in AWS Lambda with Spring Boot

class CheckIfArrayContainsValue { public static void main(String[] args) { String[] programmingLanguages = {“Python”, “Kotlin”, “Ruby”, “JavaScript”, “C#”, “Java”, “Flutter”}; for (String lang : programmingLanguages) { if (lang.equals(“Java”)) { System.out.println(“It does contain!”); break; // value found, exit the loop } } } } Output: It does contain!   Here, we are iterating over the array, and…

Read More Check if Array Contains a Value in Java

Output: Some String   Here, we put the creation of the Scanner object into a try-with-resources because we want to close the Scanner after it reads all the data. We passed the “\\A” to tell the Scanner to read the entire input stream. import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; class ConvertInputStreamToString { /** *…

Read More Convert InputStream to a String in Java

In this tutorial, we will explore different methods to find duplicate elements in a Java array, including using nested loops, sets, streams, and hash tables. We will also discuss the time and space complexity of each method, so you can choose the most efficient one for your specific use case. Whether you’re a beginner or…

Read More How to Find Duplicate Elements in a Java Array

class EscapeDoubleQuotesInString { public static void main(String[] args) { String str = “Hello, I’m \”Steve\” and I am \”Java\” developer”; System.out.println(str); } } Output: Hello, I’m “Steve” and I am “Java” developer Escape double quotes in a JSON object in Java There are many cases where you might need to escape double quotes. In this…

Read More Escape Double Quotes in Java String

Internationalization (i18n) is the process of making your application and services capable of delivering in different languages. This tutorial will show how the Spring Boot framework manages internationalization. Overview The internet has become global, implying that any application or website can target millions of users worldwide. Although half of the world’s population may have access…

Read More Spring MVC Internationalization Tutorial

<dependency> <groupid>org.apache.poi</groupid> <artifactid>poi-ooxml</artifactid> <version>5.0.0</version> </dependency> If you are not familiar with Maven, you can check out this tutorial: Create Java Project with Maven. import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; @Data @AllArgsConstructor @NoArgsConstructor public class Product { private int id; private String color; private String size; private int cost; private String description; } import org.apache.poi.ss.usermodel.Cell;…

Read More Read and write Excel files in Java

<dependency> <groupid>io.projectreactor</groupid> <artifactid>reactor-test</artifactid> <version>3.1.0.RELEASE</version> <scope>test</scope> </dependency> class ReactiveJavaTutorialTest { @Test public void testFlux() { //Create a Flux Flux <Integer> fluxToTest = Flux.just(1, 2, 3, 4, 5); // Create a test StepVerifier.create(fluxToTest) .expectNext(1) .expectNext(2) .expectNext(3) .expectNext(4) .expectNext(5) .expectComplete() // we expect Flux to complete after sending the number 5 which is the last element .verify(); }…

Read More Testing with StepVerifier in Project Reactor

class ReactiveJavaTutorial { public static void main(String[] args) { Flux<String> cities = Flux.fromIterable( new ArrayList<>(Arrays.asList(“New York”, “London”, “Paris”, “Toronto”, “Rome”))); cities.log().subscribe(); } } Output: INFO 6832 — [ main] reactor.Flux.Iterable.1 : | onSubscribe([Synchronous Fuseable] FluxIterable.IterableSubscription) INFO 6832 — [ main] reactor.Flux.Iterable.1 : | request(unbounded) INFO 6832 — [ main] reactor.Flux.Iterable.1 : | onNext(New York) INFO…

Read More Implementing Backpressure in Project Reactor

class ReactiveJavaTutorial { public static void main(String[] args) { Flux<String> cities = Flux.just(“New York”, “London”, “Paris”, “Amsterdam”) .map(String::toUpperCase) .filter(cityName -> cityName.length() <= 8) .map(cityName -> cityName.concat(” City”)) .log(); cities.subscribe(); } Output: INFO 14040 — [main] reactor.Flux.MapFuseable.1 : | onSubscribe([Fuseable] FluxMapFuseable.MapFuseableSubscriber) INFO 14040 — [main] reactor.Flux.MapFuseable.1 : | request(unbounded) INFO 14040 — [main] reactor.Flux.MapFuseable.1 : |…

Read More subscribeOn and publishOn operators in Project Reactor

class ReactiveJavaTutorial { public static void main(String[] args) { Flux<String> cities = Flux.just(“New York”, “London”, “Paris”, “Amsterdam”) .map(String::toUpperCase) .filter(cityName -> cityName.length() <= 8) .map(cityName -> cityName.concat(” City”)) .log(); cities.subscribe(); } } INFO 14040 — [main] reactor.Flux.MapFuseable.1 : | onSubscribe([Fuseable] FluxMapFuseable.MapFuseableSubscriber) INFO 14040 — [main] reactor.Flux.MapFuseable.1 : | request(unbounded) INFO 14040 — [main] reactor.Flux.MapFuseable.1 : |…

Read More Reactor Execution Model – Threading and Schedulers

This tutorial will teach you how to use Keycloak to secure your Spring Boot Application. To find other tutorials, check the Keycloak tutorials page. What is Keycloak? According to Keycloak’s  official website, It is an open-source Identity and Access Management solution aimed at modern applications and services. It makes it easy to secure applications and…

Read More A Guide to use Keycloak with Spring Boot