Determine the Class of a Generic Type in Java
1. Overview Generics, which was released in Java 5, allowed developers to create classes, interfaces, and methods with typed parameters, enabling the writing of type-safe code. Extracting this type of...
View ArticleJava System.currentTimeMillis() Vs. System.nanoTime()
1. Introduction Two commonly used mеthods for timе mеasurеmеnt in Java arе Systеm.currеntTimеMillis() and Systеm.nanoTimе(). Whilе both mеthods providе a way to mеasurе timе, thеy sеrvе diffеrеnt...
View ArticleDead Letter Queue for Kafka With Spring
1. Introduction In this tutorial, we’ll learn how to configure a Dead Letter Queue mechanism for Apache Kafka using Spring. 2. Dead Letter Queues A Dead Letter Queue (DLQ) is used to store messages...
View ArticleUsing XML in @RequestBody in Spring REST
1. Overview While JSON is a de-facto standard for RESTful services, in some cases, we might want to work with XML. We can fall back to XML for different reasons: legacy applications, using a more...
View ArticleReturn Map instead of List in Spring Data JPA
1. Overview Spring JPA provides a very flexible and convenient API for interaction with databases. However, sometimes, we need to customize it or add more functionality to the returned collections....
View ArticleCompress and Uncompress Byte Array Using Deflater/Inflater
1. Overview Data compression is a crucial aspect of software development that enables efficient storage and transmission of information. In Java, the Deflater and Inflater classes from the...
View ArticleDifference Between 1L and (long) 1
1. Overview In this tutorial, we’ll explore the differences between the literal representation of a long type and the conversion of an int value to a long value using the cast operator. 2. Literal...
View ArticleWhen to Use the getReferenceById() and findById() Methods in Spring Data JPA
1. Overview JpaRepository provides us with basic methods for CRUD operations. However, some of them are not so straightforward, and sometimes, it’s hard to identify which method would be the best for a...
View ArticleBind Case Insensitive @Value to Enum in Spring Boot
1. Overview Spring provides us with autoconfiguration features that we can use to bind components, configure beans, and set values from a property source. @Value annotation is useful when we don’t want...
View ArticleFixing Hibernate QueryException: Named Parameter Not Bound
1. Overview In this short tutorial, we’ll shed light on how to solve the Hibernate QueryException: “named parameter not bound”. First, we’ll elucidate the main cause behind the exception. Then, we’ll...
View ArticleConvert String to long or Long in Java
1. Overview In this tutorial, we’ll explore how to convert a String to a long primitive or Long object. Let’s suppose we have a String whose value reflects a number just outside the range of a signed...
View ArticleJava’s String.length() and String.getBytes().length
1. Overview When we work in Java, manipulating strings is one of the fundamental skills. So, understanding string-related methods is crucial for writing efficient and error-free code. Two commonly used...
View ArticleSending Data to a Specific Partition in Kafka
1. Introduction Apache Kafka is a distributed streaming platform that excels in handling massive real-time data streams. Kafka organizes data into topics and further divides topics into partitions....
View ArticleJava Weekly, Issue 523
1. Spring and Java >> Using AI to Create JFR Event Descriptions [foojay.io] Having fun with JFR events and GPT: generating descriptions for different JFR events via GenAI >> Quarkus...
View ArticleFind Missing Number From a Given Array in Java
1. Overview Finding the missing number from a specified range within an array in Java can be useful in various scenarios, such as data validation, ensuring completeness, or identifying gaps in a...
View ArticleRemove Null Objects in JSON Response When Using Spring and Jackson
1. Overview JSON is a de-facto standard for RESTful applications. Spring uses the Jackson library to convert objects into and from JSON seamlessly. However, sometimes, we want to customize the...
View ArticleDifference Between Xmx and MaxRAM JVM Parameters
1. Overview Heap size is an essential parameter of Java applications. It directly affects how much memory we can use and indirectly impacts the applications’ performance. For example, the usage of...
View ArticleIntroduction to Spring AI
1. Overview Spring Framework officially enabled the power of AI generative prompts with the Spring AI project. This article aims to provide a robust introduction to the generative AI integration in the...
View ArticleCreating Reactive APIs With Micronaut and MongoDB
1. Overview In this tutorial, we’ll explore how to create reactive REST APIs with Micronaut and MongoDB. Micronaut is a framework for constructing microservices and serverless applications on the Java...
View ArticleRead Multiple Messages with Apache Kafka
1. Overview In this tutorial, we’ll explore how the Kafka Consumer retrieves messages from the broker. We’ll learn the configurable properties that can directly impact how many messages the Kafka...
View Article