Java Weekly, Issue 540
1. Spring and Java >> The best way to use the JPA OneToOne optional attribute [vladmihalcea.com] Avoiding n+1 query issues by taking advantage of attributes of OneToOne in JPA >> Spring AI:...
View ArticleConvert From int to short in Java
1. Overview When we work with Java, we often encounter scenarios where we need to convert data types to suit specific requirements. One common conversion is from int to short. In this tutorial, we’ll...
View ArticleCompare the Numbers of Different Types
1. Overview Sometimes, we must compare the numbers, ignoring their classes or types. This is especially helpful if the format isn’t uniform and the numbers might be used in different contexts. In this...
View ArticleassertEquals() vs. assertSame() in JUnit
1. Overview JUnit is a popular testing framework. As a part of its API, it provides a convenient way to check and compare objects. However, the difference between the two methods, assertEquals() and...
View ArticlePrint Distinct Characters of a String in Java
1. Introduction In Java programming, printing distinct characters from a string is a fundamental task often required in text processing and analysis. In this tutorial, we’ll explore various approaches...
View ArticleHow to Use Pair With Java PriorityQueue
1. Overview The PriorityQueue is one of the most powerful data structures. It’s uncommon in enterprise applications, but we often use it for coding challenges and algorithm implementations. In this...
View ArticleConverting Float ArrayList to Primitive Array in Java
1. Overview Sequences of data are integral to any project and any programming language. In Java, there are two ways to represent a sequence of elements: Collections and arrays. In this tutorial, we’ll...
View ArticleHandling Nulls in ArrayList.addAll()
1. Overview Working comfortably with Collection API is one of the most crucial skills of a Java developer. In this tutorial, we’ll concentrate on the ArrayList and its addAll() method. While addAll()...
View ArticleAuthenticate Using Social Login in Spring Authorization Server
1. Introduction In this tutorial, we’ll demonstrate how to setup the back end of a web application that uses Spring’s social login feature. We’ll use Spring Boot and the OAuth2.0 dependency. We’ll also...
View ArticleRemove All Characters Before a Specific Character in Java
1. Introduction When working with strings in Java, we may encounter scenarios where we need to remove all characters before a particular delimiter or character. Fortunately, we can accomplish this task...
View ArticleFinding The Index of the Smallest Element in an Array
1. Overview Operations on arrays are essential, and we might need them in any application. Sometimes, they’re hidden behind more convenient interfaces like Collections API. However, this is the basic...
View ArticleConvert 2D Array Into 1D Array
1. Overview Arrays are the most basic data structures in any language. Although we don’t work on them directly in most cases, knowing how to manipulate them efficiently can dramatically improve our...
View ArticleHow to Test a Spring AOP Aspect
1. Overview Aspect-oriented programming (AOP) improves program design by separating a cross-cutting concern into a base unit, called an aspect, from the main application logic. Spring AOP is a...
View ArticleGenerate Java Classes From Avro Schemas Using Gradle
1. Overview In this tutorial, we’ll learn how to generate Java classes from an Apache Avro schema. First, we’ll familiarize ourselves with two methods: using the existing Gradle plugin and implementing...
View ArticleDifference Between Lombok @AllArgsConstructor, @RequiredArgsConstructor and...
1. Overview Project Lombok reduces boilerplate code in Java applications by providing annotations that automatically generate commonly used code. In this tutorial, we’ll explore the differences between...
View ArticleIntroduction to Java 22
1. Introduction In this tutorial, we’ll dive deep into the latest Java release, Java 22, which is now in General Availability. 2. Java Language Updates Let’s talk about all the new changes to the Java...
View ArticleGet JSON Content as Object Using MockMVC
1. Overview When testing our REST endpoints, sometimes we want to obtain the response and convert it to an object for further checking and validation. As we know, one way to do this is by using...
View ArticleUsing MapStruct With Inheritance
1. Overview MapStruct is a Java annotation processor that comes in handy when generating type-safe and effective mappers for Java bean classes. In this tutorial, we’ll specifically learn how to use the...
View ArticleHow to Unit Test an ExecutorService Without Using Thread.sleep()
1. Overview An ExecutorService object runs tasks in the background. Unit testing a task that runs on another thread is challenging. The parent thread must wait for the task to end before asserting its...
View ArticleMapping Enum to String Using MapStruct
1. Introduction MapStruct is an efficient, type-safe library that simplifies data mapping between Java objects, eliminating the need for manual conversion logic. In this tutorial, we’ll explore the use...
View Article