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

Gotcha: Using Apache Commons StringUtils.isNumeric

StringUtils java class in Apache commons library provides a method isNumeric to check if given sequence of characters contains digits only. But this is not a sure shot way to check for numbers because for a string containing decimal the StringUtils.isNumeric returns false as shown below: A better approach is to use NumberUtils.isCreatable which adopts … Read more

The correct way to do @Async in Java Spring based applications

Spring provides an annotation @Async to run tasks in a separate thread. In Spring boot applications we can enable asynchronous tasks by adding the annotation @EnableAsync to any of the Spring configuration class as shown below: Now that we have the application setup to support asynchronous tasks, let us go ahead and create a simple … Read more

Setting value of XSL parameter xsl:param in Saxon Java API

In one of my previous posts I showed you how to generate HTML from XML data using XSLT. At times you would need to pass certain parameters to the XSLT and use the value of that parameter in generating your content. In this post we will exactly do that. This will be our sample XML … 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

Integrate with OpenAI(ChatGPT) Completion API in Java using WebClient

By now you all would have heard about OpenAI and played with its famous product ChatGPT. OpenAI also provides APIs which can be used to integrate features like text completion, code generation, image generation and chat completion in your applications. In this post I will show you how to make use of the Text completion … 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 – Pattern matching for instanceof

We all have used instanceof check with a subsequent cast to the desired type and in this process, we are doing two operations: validating whether the object we have is of the desired type using instanceof when the validation is true then we cast the object to the desired type and proceed with the operations. … 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

%d bloggers like this: