Understanding Kafka InstanceAlreadyExistsException in Java
Baeldung » Java
by Wynn Teo
1d ago
1. Introduction Apache Kafka is a powerful distributed streaming platform that is widely used for building real-time data pipelines and streaming applications. However, Kafka may encounter various exceptions and errors during operation. One such exception that is commonly faced is the InstanceAlreadyExistsException. In this tutorial, we’ll explore the significance of this exception within Kafka. We’ll also delve into its root causes and effective Java application handling techniques. 2. What Is InstanceAlreadyExistsException? The InstanceAlreadyExistsException is a subclass of the java.lang.Ru ..read more
Visit website
Add Camel Route at Runtime in Java
Baeldung » Java
by Olayemi Michael
1d ago
1. Overview Apache Camel is a Java framework that makes it easy to implement various Enterprise Integration Patterns (EIPs) for providing solutions to enterprise integration. One of the common tasks in an integration pattern is to determine the message route at a runtime based on specific rules and conditions. Apache Camel simplifies this process by providing a method to implement Dynamic Router EIP. In this tutorial, we’ll delve into details of how to implement dynamic routing in Apache Camel and walk through an example. 2. Understanding the Dynamic Router Occasionally, there are cases where ..read more
Visit website
How To Use findBy() With Multiple Columns in JPA
Baeldung » Java
by Suraj Mishra
1d ago
1. Introduction Spring Dat;u JPA provides a query derivation feature, using which we can derive queries automatically by just following the method name conventions. In this article, we’ll use the query derivation feature to find entities by one or more columns. 2. Example Setup For example purposes, we’ll use an Account entity which contains properties related to the user account: @Entity @Table(name = "ACCOUNTS") public class Account { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "accounts_seq") @SequenceGenerator(name = "accounts_seq", sequenceName = "acco ..read more
Visit website
Logging With AOP in Spring
Baeldung » Java
by Ana Peterlić
3d ago
1. Overview We often use logging to document meaningful steps and valuable information during the program execution. It allows us to record data we can use later to debug and analyze the code. Additionally, Aspect-Oriented Programming (or AOP for short) is a paradigm that lets us segregate cross-cutting concerns, such as transaction management or logging, throughout the application without cluttering the business logic. In this tutorial, we’ll learn how to implement logging using the AOP and Spring framework. 2. Logging Without AOP When it comes to logging, we usually put logs at the beginning ..read more
Visit website
Mask an Email Address and Phone Number in Java
Baeldung » Java
by baeldung
1w ago
1. Introduction Privacy and data security are important elements of software development. Masking sensitive details such as the user’s email address and phone number is usually one procedure used to safeguard user information and prevent its disclosure. In this tutorial, we’ll investigate how to mask email addresses and phone numbers in Java. 2. Masking Email Addresses 2.1. Using String Manipulation String manipulation is one of the ways to hide an email by editing the characters and replacing a few with asterisks. Here’s a simple Java code snippet demonstrating this approach: String email ..read more
Visit website
Java Weekly, Issue 529
Baeldung » Java
by baeldung
1w ago
1. Spring and Java >> Emulating C# LINQ in Java using Code Reflection [openjdk.org] Java’s LINQ Inspiration: unleashing Code Reflection Power, Emulating the LINQ in Java. >> FetchType: Lazy/Eager loading for Hibernate & JPA [thorben-janssen.com] Mastering JPA Fetch Types: a comprehensive guide to entity mappings and performance optimization. >> Hibernate StatelessSession JDBC Batching [vladmihalcea.com] And, still on the persistence track – optimizing Hibernate: exploring StatelessSession and JDBC Batching. Also worth reading: >> JDK 22 G1/Parallel/Serial GC c ..read more
Visit website
Preventing Gson from Expressing Integers as Floats
Baeldung » Java
by baeldung
1w ago
1. Introduction The Gson library developed by Google is quite a good choice for serialization and deserialization of Java objects to and from JSON format. Besides, we typically come across the problem that Gson shows integers as floating-point numbers while serializing objects. In this tutorial, we’ll see why integers are considered floating-point numbers. Moreover, we’ll provide a solution to prevent Gson from doing that. 2. Problem Definition Gson serializes Java objects to JSON. By default, Gson serializes integers as floating-point numbers for a more accurate representation. Here’s a simpl ..read more
Visit website
How to Collect All Results and Handle Exceptions With CompletableFuture in a Loop
Baeldung » Java
by Lucian Snare
1w ago
1. Overview Java 8’s CompletableFuture is well-suited to handling asynchronous computation. For instance, a web client may employ CompletableFuture when making a server call. It’s easy to get started and handle an individual CompletableFuture response. However, it’s not immediately clear how to collect the results of multiple CompletableFuture executions while also handling exceptions. In this tutorial, we’ll develop a simple mock microservice client that returns a CompletableFuture, and see how to call it multiple times to generate a summary of successes and failures. 2. An Example  ..read more
Visit website
Collect Stream of entrySet() to a LinkedHashMap
Baeldung » Java
by Daniel McNally
1w ago
1. Overview In this tutorial, we’ll explore the different ways to collect a stream of Map.Entry objects into a LinkedHashMap. A LinkedHashMap is similar to HashMap but differs in the respect that it maintains the insertion order.  2. Understanding the Problem We can obtain a stream of map entries by invoking the entrySet() method followed by the stream() method. This stream gives us the ability to process each entry. Processing is achieved via intermediate operations and can involve filtering via the filter() method or transforming via the map() method. Ultimately, we must decid ..read more
Visit website
Find the First Non-repeating Element of a List
Baeldung » Java
by Wynn Teo
1w ago
1. Introduction In this tutorial, we’ll explore the problem of finding the first non-repeating element in a list. We’ll first understand the problem statement and then implement a few methods to achieve the desired outcome. 2. Problem Statement Given a list of elements, the task is to find the first element that doesn’t repeat in the list. In other words, we need to identify the first element that appears only once in the list. If there are no non-repeating elements, we then return an appropriate indication, e.g., null. 3. Using for Loop This method uses nested for loops to iterate through the ..read more
Visit website

Follow Baeldung » Java on FeedSpot

Continue with Google
Continue with Apple
OR