Java EnumSet and EnumMap made simple

The EnumMap and EnumSet are specialized implementations in Java that are optimized for working with Enum keys and Enum values, respectively. In this article we will learn how to use them and which are the common use cases. Finally, we will also highlight the differences with the standard Map and Set objects.

Read more

Default parameters for Java methods

Java lacks direct support for default parameter values as seen in some other programming languages. However, there are several techniques and patterns you can utilize to achieve similar functionality. In this tutorial, we’ll explore five different approaches to emulate default parameter values in Java. 1. Method Overloading Method overloading involves creating multiple versions of a … Read more

Fastest way to sort an Array in Java

Sorting arrays efficiently is crucial for optimizing performance in Java applications. With numerous sorting algorithms and built-in methods available, it’s essential to identify the most efficient approach for different scenarios. Let’s delve into a comparative analysis of various sorting methods to determine the fastest way to sort a Java array. Introduction Sorting large arrays efficiently … Read more

Comparing Java Records with Lombok

Java records and Lombok are both tools that aim to reduce boilerplate code in Java, but they have different approaches and use cases. In this article we will compare them to understand which is the perfect use case of each approach. Java Records overview: For example: Lombok Library overview: For example: Please note that, in … Read more

Converting JSON to Java Map using Jackson

This tutorial demonstrates how to convert a JSON string into a Java Map using Jackson’s ObjectMapper. We will show a basic Java main Class to convert a sample JSON String. Then, we will simplify the classpath set up using JBang. Prerequisites Steps: 1. Include Jackson Dependency Make sure to include the Jackson dependencies in your … Read more

How to solve java.lang.NoClassDefFoundError: javax/xml/bind Classes

The java.lang.NoClassDefFoundError: javax/xml/bind/JAXBException error (or other javax.xml.bind classes) typically arises due to missing JAXB API in your Classpath or Runtime. Here’s how to resolve it. Understanding the Issue In Java 9 onwards, the Java EE APIs, including JAXB (Java Architecture for XML Binding), are not included by default. These APIs were traditionally bundled with Java … Read more

How to convert a Map to JSON in Java

When working with Java, it’s often necessary to convert data structures to and from different formats, especially when dealing with JSON data. Fortunately, libraries like Jackson provide robust support for JSON processing, allowing seamless conversion between Java objects and JSON representations. In this article, we’ll explore how to convert a Map to a JSON object using Jackson in Java.

Read more

How to check the content of a Java KeyStore

Java KeyStores (JKS) provide a secure way to store sensitive data, and they can be used by Java applications to encrypt and decrypt data, authenticate users, and secure network communications. In this tutorial we will check three ways to read the content of a KeyStore information such as the alias the the Certificate.

Read more