Baeldung » Java
1,267 FOLLOWERS
Baeldung helps developers explore the Java ecosystem and simply be better engineers. Java is the popular programming language that originated in 1995. Today, the Java ecosystem includes a very large number of specifications, libraries, frameworks, tools, as well as a thriving community. Take a dive through our collection of Java tutorials that cover a wide array of Java-related topics.
Baeldung » Java
9h ago
1. Overview
Moving averages are a fundamental tool in analyzing trends and patterns in data and are widely used in finance, economics, and engineering.
They help smooth out short-term fluctuations and reveal underlying trends, making data easier to interpret.
In this tutorial, we’ll explore various methods and techniques for calculating moving averages, ranging from traditional approaches to libraries and Stream API’s.
2. Common Methods for Calculating Moving Averages
In this section, we’ll explore three common methods for calculating moving averages.
2.1. Using Apache Commons Math Library
Apa ..read more
Baeldung » Java
9h ago
1. Overview
Persistence context and persistence unit are two important concepts in JPA that we use to manage the lifecycle of entities in an application.
In this tutorial, we’ll take a look at a brief introduction to entity manager and entity manager factory. Next, we’ll see why persistence context is important and its use cases. Finally, we’ll see the role of the persistence unit and its use cases.
2. EntityManager and EntityManagerFactory
Before diving into the details, it’s essential to have a basic understanding of the EntityManager and EntityManagerFactory interfaces. As we’ll se ..read more
Baeldung » Java
3d ago
1. Introduction
Dealing with date and time values is a common task in software development, especially when building applications that involve scheduling, logging, or any time-sensitive operations. In the same context, the OffsetDateTime class in Java provides a robust solution for representing date and time information with an offset from UTC/GMT.
In this tutorial, we’ll explore how to efficiently convert a string representing date and time information into an OffsetDateTime object in Java.
2. Using OffsetDateTime.parse() Method
One of the simplest approaches to converting a string to an Offs ..read more
Baeldung » Java
3d ago
1. Introduction
In our journey through software development, we often encounter scenarios where creating objects with numerous properties becomes intimidating. Cluttering our constructors is making our code less readable. This is precisely where the Builder Pattern shines. The Builder Pattern is a creational design pattern that separates the construction of complex objects from their representation, offering a cleaner and more flexible approach to object creation.
2. Advantages of Builder Pattern
Before we dive into coding, let’s quickly recap the advantages of utilizing the Builder Pattern ..read more
Baeldung » Java
3d ago
1. Overview
Manipulating Strings is a fundamental task when we work with Java. We often need to convert other data types into Strings. Two common approaches for accomplishing this are casting to String and using the String.valueOf() method. They might seem similar on the surface, but some differences between the two methods may affect our code’s behavior.
In this quick tutorial, let’s discuss the differences between them.
2. Casting to String and String.valueOf()
First, let’s look at an example. Let’s say we assigned a String value to a variable with the type Object:
Object obj = "Baeldu ..read more
Baeldung » Java
3d ago
1. Introduction
In application development, the need to perform an update-or-insert operation, also known as “upsert”, is quite common. This operation involves putting a new record into a database table if it doesn’t exist or updating an existing record if it does.
In this tutorial, we’ll learn different approaches to performing update-or-insert operations using Spring Data JPA.
2. Setup
For demo purposes, we’ll use a CreditCard entity:
@Entity
@Table(name="credit_card")
public class CreditCard {
@Id
@GeneratedValue(strategy= GenerationType.SEQUENCE, generator = "credit_card_id_seq ..read more
Baeldung » Java
4d ago
1. Overview
The GZIP format is a file format used in data compression. The GZipInputStream and GZipOutputStream classes of the Java language implement this file format.
In this tutorial, we’ll learn how to compress data using GZIP in Java. Also, we’ll look at how we can write the compressed data into a byte array.
2. The GZipOutputStream Class
The GZipOutputStream class compresses and writes data to an underlying output stream.
2.1. Object Instantiation
We can use the constructor to create an object of the class:
ByteArrayOutputStream os = new ByteArrayOutputStream();
GZIPOutputStream gzipOs ..read more
Baeldung » Java
4d ago
1. Overview
When using Spring Data JPA we may encounter issues during the bootstrap time. Some of the beans may not be created, causing the application not to start. While the actual stack trace may vary, generally, it looks like this:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerAdapter'
...
Caused by: java.lang.IllegalArgumentException: Not a managed type: ...OurEntity
at org.hibernate.metamodel.internal.MetamodelImpl.managedType(MetamodelImpl.java:583)
at org.hibernate.metamodel.internal.MetamodelImpl.managedTy ..read more
Baeldung » Java
6d ago
1. Spring and Java
>> JEP 473: Stream Gatherers (Second Preview) [openjdk.org]
The second preview of Stream Gatherers in Java 23 — going beyond pre-defined intermediate operations in Stream API
>> Modernizing Testing Practices for Jakarta EE Projects [infoq.com]
Anatomy of testing in modern Jakarta EE applications: guidelines, data-driven, extensive assertions, coverage, and more
>> Spring Framework 6.2.0-M1: all the little things [spring.io]
And some small yet very useful additions in Spring Framework: escaping property placeholders, fallback beans, background initializ ..read more
Baeldung » Java
1w ago
1. Overview
In this tutorial, we’ll understand why the Easter date is complex to compute. Then, we’ll implement three algorithms to calculate it in Java: the Gauss, Butcher-Meeus, and Conway algorithms.
2. History of the Catholic Easter Sunday
Easter is a holiday that celebrates the resurrection of Jesus Christ from the dead. Easter’s timing was initially tied to the Jewish Passover, as the last supper of Jesus with his disciples was a Passover meal. However, during the first centuries, each Christian community could elect a date to celebrate it, leading to some controversy. The Council of Nic ..read more