Unveiling the Magic of Java ServiceLoader API: Building Modular and Extensible Applications

In the vast realm of Java programming, developers are often faced with the challenge of creating modular, extensible, and maintainable applications. As software systems grow in complexity, the need to decouple components and facilitate dynamic plugin loading becomes paramount. This is where the Java ServiceLoader API shines, offering a robust and elegant solution for achieving … Read more

Integrate with OpenAI(ChatGPT) Chat Completion API in Java using Webclient

In my previous post I showed how you can integrate with Completion API. The completion API doesnt support the ChatpGPT model. The ChatGPT model is supported in the Chat completion API. In this post we will look at integrating with this new API using WebClient. Below are the POJOs we will be using for parsing … Read more

Java 17 – Sealed classes

Prior to Sealed Classes feature there were two ways a developer could prevent a class to be extended: 2. by making the class package private where no one outside the package can access the class and hence no one outside the package can extend the class. The first approach is very restrictive but the superclass … Read more

Java 16 – Records and Constructor

In my previous post, I introduced you to the new construct called Records which was introduced in Java 16. In this post, I will go a bit deeper into how you can override the default constructor of a record which is different from the no-arg default constructor of a class. Default constructor in a record … Read more

Java 16 – Records

We all, Java programmers, have complained whenever we were forced to create a class or use maps just to hold some data whilst other newer languages provided some out-of-the-box data structure for the same. Our problem has been addressed by introducing “Records” as part of the JEP 395 in Java 16. This construct is introduced … Read more

Difference between Function.andThen and Function.compose

There are two different ways to mix functions in Java: using andThen using compose It is important to understand the difference between the two. andThen: function1.andThen(function2) will first apply function1 to the input and the result of this will be passed to the function2. compose: function1.compose(function2) will first apply the input to the function2 and … Read more

Sample Logback Configuration for Spring Boot Profile Based Logging

We would want different logging configurations for different profiles in Spring Boot, like in local running we would just want console logging and for production, we would want file logging with support for rolling the log files daily. I came up with a sample logback configuration which I use in all my applications. Create a … Read more

Getting to know about java.nio.file.Path – 2

In Part 1 of this, we looked at most of the APIs in the java.nio.file.Path class. In this article, we will look at the remaining APIs. Using register() This API allows us to register an implementation of java.nio.file.WatchService interface which will listen for events like directory creation, modification, and deletion. And it intimates the listeners … Read more

Getting to know about java.nio.file.Path – 1

Introduction The last few released of Java namely Java 7, Java 8 and the upcoming Java 9 have quite a lot of features which makes the life of Java developers easier. (I know Java 9 will make it tougher, but only while you adopt the new paradigm. After that it’s going to be much better). … Read more