baeldung

Java Weekly, Issue 374

1. Spring and Java >> Optional.stream() [blog.frankel.ch] Streaming optional values – simplifying optional pipelines by converting them to streams! >> Initialization Strategies With Testcontainers For Integration Tests [rieckpil.de] Setting up containers with TestContainers – executing commands, mounting files, init scripts, and prepopulating databases. >> Faster Charset Decoding [cl4es.github.io] Better decoding for Java 17:...

baeldung

Optimizing HashMap’s Performance

1. Introduction HashMap is a powerful data structure that has a broad application, especially when fast lookup time is needed. Yet, if we don't pay attention to details, it can get suboptimal. In this tutorial, we'll take a look at how to make HashMap as fast as possible. 2. HashMap‘s Bottleneck HashMap‘s optimistic constant time of element retrieval (O(1)) comes from the power of hashing. For each element, HashMap computes the...

baeldung

Override Maven Plugin Configuration from Parent

1. Overview In a Maven multi-module project, the effective POM is the result of merging all configurations defined within a module and its parents. In order to avoid redundancies and duplication between modules, we often keep common configurations in the shared parent. However, there can be a challenge if we need to have a custom configuration for a child module without impacting all its siblings. In this tutorial, we'll learn how to...

baeldung

Configuring Message Retention Period in Apache Kafka

1. Overview When a producer sends a message to Apache Kafka, it appends it in a log file and retains it for a configured duration. In this tutorial, we'll learn to configure time-based message retention properties for Kafka topics. 2. Time-Based Retention With retention period properties in place, messages have a TTL (time to live). Upon expiry, messages are marked for deletion, thereby freeing up the disk space. The same retention...

baeldung

Java Warning “Unchecked Cast”

1. Overview Sometimes, when we compile our Java source files, we see “unchecked cast” warning messages printed by the Java compiler. In this tutorial, we're going to take a closer look at the warning message. We'll discuss what this warning means, why we're warned, and how to solve the problem. Some Java compilers suppress unchecked warnings by default. Let's make sure we've enabled the compiler's option to print “unchecked”...

baeldung

“HttpMessageNotWritableException: No converter found for return value of type”

1. Overview In this tutorial, we're going to shed light on Spring's HttpMessageNotWritableException: “No converter found for return value of type” exception. First, we'll explain the main causes of the exception. Then, we'll dig deeper to see how to produce it using a real-world example and finally how to fix it. 2. The Causes Typically, this exception occurs when Spring fails to fetch the properties of a returned object. The...

baeldung

Spring @Component Annotation

1. Overview In this tutorial, we'll take a comprehensive look at the Spring @Component annotation and related areas. By the end, we'll see the different ways we can use it to integrate with some core Spring functionality and how we can take advantage of its many benefits. 2. Spring ApplicationContext Before we can understand the value of @Component, we must first understand a little bit about the Spring ApplicationContext. This is...

baeldung

Configure the Heap Size When Starting a Spring Boot Application

1. Introduction In this tutorial, we'll learn how to configure the heap size when we start a Spring Boot application. We'll be configuring the -Xms and -Xmx settings, which correspond to starting and maximum heap size. Then, we'll use Maven first to configure the heap size when starting the application using mvn on the command-line. We'll also look at how we can set those values using the Maven plugin. Next, we'll package our...

baeldung

File Upload With Open Feign

1. Overview In this tutorial, we'll demonstrate how to upload a file using Open Feign. Feign is a powerful tool for microservice developers to communicate via REST API with other microservices in a declarative manner. 2. Prerequisite Let's assume that a RESTful web service is exposed for a file upload, and given below are the details: POST http://localhost:8081/upload-file So, to explain the file upload via Feign client, we'll call...