Rotating a Java String By n Characters
1. Overview In our daily Java programming, strings are often the fundamental objects we must handle. Sometimes, we need to rotate a given string by n characters. Rotating a string involves shifting its...
View ArticleGet Client Information From HTTP Request in Java
1. Overview Web applications mainly work on the request-response model, and this model describes data exchange between a client and a web server using HTTP protocol. At the server end, which accepts or...
View ArticleSorting One List Based on Another List in Java
1. Overview Sorting a list based on the order of another list is a common task in Java, and various approaches exist to achieve this. In this tutorial, we’ll see different ways of sorting a list based...
View ArticleCheck If a Java StringBuilder Object Contains a Character
1. Introduction Thе StringBuildеr class in Java provides a flеxiblе and еfficiеnt way to manipulatе strings. In some cases, we nееd to chеck whеthеr a StringBuildеr objеct contains a specific...
View Article@Query Definitions With SpEL Support in Spring Data JPA
1. Overview SpEL stands for Spring Expression Language and is a powerful tool that can significantly enhance our interaction with Spring and provide an additional abstraction over configuration,...
View ArticleJava Weekly, Issue 522
1. Spring and Java >> Hibernate StatelessSession Upsert [vladmihalcea.com] A portable way of performing an upsert using Hibernate StatelessSession’s Upsert method. Interesting. >> This Year...
View ArticleDetermine 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 ArticleUnreachable Statements in Java
1. Overview In this tutorial, we’ll talk about the Java specification that states that the compiler should raise an error if any statement is unreachable. An unreachable statement is a code that can...
View ArticleCreate a Mutable String in Java
1. Introduction In this tutorial, we’ll discuss a few ways to create a mutable String in Java. 2. Immutability of Strings Unlike other programming languages like C or C++, Strings are immutable in...
View ArticleConvert a Hex String to an Integer in Java
1. Introduction Converting a hexadecimal (Hex) string into an integer is a frequent task during programming, particularly when handling data types that use hexadecimal notations. In this tutorial,...
View ArticleSplitting Streams in Kafka
1. Introduction In this tutorial, we’ll explore how to dynamically route messages in Kafka Streams. Dynamic routing is particularly useful when the destination topic for a message depends on its...
View ArticleComparing the Values of Two Generic Numbers in Java
1. Introduction Java’s versatility is evident in its ability to handle generic Number objects. In this tutorial, we’ll delve into the nuances of comparing these objects, offering detailed insights and...
View Article