Author: Vijay SRJ

  • Java 21 – Sequenced Collections

    How do you get the last element of a list in Java? Using a code similar to below: That doesn’t look elegant! And how do you get the last element for a Sorted Set? That looks much more elegant but then different collections are having different ways to get the last element. There is no…

  • Java 21 – String templates

    Contents: The Problem “String” is a basic and widely used data type in any programming language. Most of the data we deal with are texts which are represented by String datatype. One of the operations we often do on text is replacing part of the text with dynamic values . This is called interpolation. Languages…

  • Java 21 Features – Unnamed classes and instance main methods

    Java 21 Features – Unnamed classes and instance main methods

    Java 21 allows you to print Hello World message without creating a class and using public static keyword for main class.

  • Java 21 – Unnamed Patterns and Variables

    Java 21 – Unnamed Patterns and Variables

    Let’s say you have declared a variable in your Java program. But you are not going to use it for some reason. May be you declared an exception variable in a catch block but not going to use the variable at all: Or in a for loop statement: Or in Pattern Matching of Records (introduced…

  • How to implement Circuit Breaker Design Pattern in Spring Boot?

    How to implement Circuit Breaker Design Pattern in Spring Boot?

    Table of Contents: Problem: Fault tolerance is a major requirement for enterprise applications. If your application gets huge load , how does it behave? If something wrong happens within your application and you still want to handle it gracefully , what do you do? Fault tolerance is especially important for microservices since many microservices communicate…

  • How to implement SAGA design pattern in Spring Boot?

    How to implement SAGA design pattern in Spring Boot?

    Contents: Problem: Microservices come with their own advantages and disadvantages. One such disadvantage is managing distributed transactions. Let’s say your transaction spans 4 different microservices. How do you ensure that your transaction either commits successfully with all the 4 tasks succeeding or fails successfully if any of the tasks is not completed ( the completed…

  • Java 21 – Record Patterns

    Pattern Matching is a new area where Java has been introducing quite a few changes recently. It started with instanceof operator. Previously in Java , if you had to access an object whose instance type you didnt know prior, you had to use instanceof operator this way: You had to do a cast operation as…

  • How to implement CQRS design pattern in Spring Boot?

    How to implement CQRS design pattern in Spring Boot?

    Contents Problem: Let’s say you run a large scale ecommerce store. You have a large user base who query your system for products much more than they buy them. In other words , your system has more read requests than write requests. And so you would like to handle the high load of read requests…

  • How to configure sensitive configuration details in your Angular app without being visible to the front end user?

    Often in your angular app you need to configure sensitive data like credentials. You can store this in your code but then it will be visible to any one who loads your angular app in their browser. You can store it in a config file under assets directory , still it might be exposed to…

  • How to share data across multiple components for a single request in a Spring Boot application?

    How to share data across multiple components for a single request in a Spring Boot application?

    Let’s say that you make a REST API request to a spring boot web application. There is a security requirement that you need to log the user id across all the method calls in the application for this particular request. Something like this: So , if your application flow starts from a controller class and…