eBook – Guide Spring Cloud – NPI EA (cat=Spring Cloud)
announcement - icon

Let's get started with a Microservice Architecture with Spring Cloud:

>> Join Pro and download the eBook

eBook – Mockito – NPI EA (tag = Mockito)
announcement - icon

Mocking is an essential part of unit testing, and the Mockito library makes it easy to write clean and intuitive unit tests for your Java code.

Get started with mocking and improve your application tests using our Mockito guide:

Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Reactive – NPI EA (cat=Reactive)
announcement - icon

Spring 5 added support for reactive programming with the Spring WebFlux module, which has been improved upon ever since. Get started with the Reactor project basics and reactive programming in Spring Boot:

>> Join Pro and download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Jackson – NPI EA (cat=Jackson)
announcement - icon

Do JSON right with Jackson

Download the E-book

eBook – HTTP Client – NPI EA (cat=Http Client-Side)
announcement - icon

Get the most out of the Apache HTTP Client

Download the E-book

eBook – Maven – NPI EA (cat = Maven)
announcement - icon

Get Started with Apache Maven:

Download the E-book

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

eBook – RwS – NPI EA (cat=Spring MVC)
announcement - icon

Building a REST API with Spring?

Download the E-book

Course – LS – NPI EA (cat=Jackson)
announcement - icon

Get started with Spring and Spring Boot, through the Learn Spring course:

>> LEARN SPRING
Course – RWSB – NPI EA (cat=REST)
announcement - icon

Explore Spring Boot 3 and Spring 6 in-depth through building a full REST API with the framework:

>> The New “REST With Spring Boot”

Course – LSS – NPI EA (cat=Spring Security)
announcement - icon

Yes, Spring Security can be complex, from the more advanced functionality within the Core to the deep OAuth support in the framework.

I built the security material as two full courses - Core and OAuth, to get practical with these more complex scenarios. We explore when and how to use each feature and code through it on the backing project.

You can explore the course here:

>> Learn Spring Security

Course – LSD – NPI EA (tag=Spring Data JPA)
announcement - icon

Spring Data JPA is a great way to handle the complexity of JPA with the powerful simplicity of Spring Boot.

Get started with Spring Data JPA through the guided reference course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (cat=Spring Boot)
announcement - icon

Refactor Java code safely — and automatically — with OpenRewrite.

Refactoring big codebases by hand is slow, risky, and easy to put off. That’s where OpenRewrite comes in. The open-source framework for large-scale, automated code transformations helps teams modernize safely and consistently.

Each month, the creators and maintainers of OpenRewrite at Moderne run live, hands-on training sessions — one for newcomers and one for experienced users. You’ll see how recipes work, how to apply them across projects, and how to modernize code with confidence.

Join the next session, bring your questions, and learn how to automate the kind of work that usually eats your sprint time.

Course – LJB – NPI EA (cat = Core Java)
announcement - icon

Code your way through and build up a solid, practical foundation of Java:

>> Learn Java Basics

Partner – LambdaTest – NPI EA (cat= Testing)
announcement - icon

Distributed systems often come with complex challenges such as service-to-service communication, state management, asynchronous messaging, security, and more.

Dapr (Distributed Application Runtime) provides a set of APIs and building blocks to address these challenges, abstracting away infrastructure so we can focus on business logic.

In this tutorial, we'll focus on Dapr's pub/sub API for message brokering. Using its Spring Boot integration, we'll simplify the creation of a loosely coupled, portable, and easily testable pub/sub messaging system:

>> Flexible Pub/Sub Messaging With Spring Boot and Dapr

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 Nicea in 325 finally standardized Easter’s definition: Easter Sunday is the first Sunday following the full moon after the vernal equinox.

Calculating Easter’s date is challenging because it depends on lunar and solar calendars, and lunar cycles don’t match solar ones. Thus, mathematical algorithms came in handy to determine Easter’s date.

3. Algorithms

Let’s point out that all algorithms focus on calculating the Catholic Easter date that uses the Gregorian calendar introduced by Pope Gregory XIII at the end of the 16th century. On the other hand, some churches, like the Russian Orthodox church, still use the Julian calendar to determine Easter’s date.

Now, let’s take a look at each of the algorithms.

3.1. Gauss Algorithm

Gauss, a famous German mathematician, was the first to tackle the problem at the beginning of the 19th century. His algorithm starts with tracking approximately the lunar orbit and then determines the exact offset to obtain a Sunday following the full moon.

Let’s have a look at it:

LocalDate computeEasterDateWithGaussAlgorithm(int year) {
    int a = year % 19;
    int b = year % 4;
    int c = year % 7;
    int k = year / 100;
    int p = (13 + 8*k) / 25;
    int q = k / 4;
    int M = (15 - p + k - q) % 30;
    int N = (4 + k - q) % 7;
    int d = (19*a + M) % 30;
    int e = (2*b + 4*c + 6*d + N) % 7;
        
    if (d==29 && e == 6) {
        return LocalDate.of(year, 4, 19);
    } else if (d==28 && e==6 && ((11*M + 11)%30 < 10)) {
        return LocalDate.of(year, 4, 18);
    }
        
    int H = 22 + d + e;
    if (H <= 31) {
        return LocalDate.of(year, 3, H);
    }
    return LocalDate.of(year, 4, H-31);
}

In this code:

  • a represents the Golden Number, indicating the year’s position in the Metonic cycle
  • b is associated with leap years, ensuring accurate adjustments given February’s length
  • c keeps track of the calendar not having a leap year once a century
  • p and q are intermediate variables, and calculating them leads to determining M and N, which represent adjustments regarding the epact, the difference between the lunar and solar years
  • d is the number of days from March 21st till the Paschal full moon
  • e is the number of days between the first day after the Paschal full moon and Easter Sunday

Lastly, there are two exceptions because the Paschal full moon can never occur on April 19th, and in rare cases, when a Metonic cycle would have its preceding full moon on the same day, which is not allowed.

Our method returns a LocalDate, as it’s a natural choice for representing a date without a timezone. Additionally, we can unit-test our method: for instance, with the year 2024, assuming we called our class EasterDateCalculator:

@Test
void givenEasterInMarch_whenComputeEasterDateWithGaussAlgorithm_thenCorrectResult() {
    assertEquals(LocalDate.of(2024, 3, 31), new EasterDateCalculator().computeEasterDateWithGaussAlgorithm(2024));
}

3.2. Butcher-Meeus Algorithm

The origin of this algorithm is surprising: in 1876, an English paper called Nature received a letter from New York containing a method for Easter date calculation. One year later, Butcher, bishop of Meath, proved it was correct. Meeus popularized it in 1991 in his book Astronomical Algorithms.

Nowadays, it’s the most widely used in calendar-related software and applications.

The Butcher-Meeus algorithm enhances Gauss’s original method by incorporating refinements based on improved astronomical data and computational techniques.

Let’s implement it:

LocalDate computeEasterDateWithButcherMeeusAlgorithm(int year) {
    int a = year % 19;
    int b = year / 100;
    int c = year % 100;
    int d = b / 4;
    int e = b % 4;
    int f = (b + 8) / 25;
    int g = (b - f + 1) / 3;
    int h = (19*a + b - d - g + 15) % 30;
    int i = c / 4;
    int k = c % 4;
    int l = (2*e + 2*i - h - k + 32) % 7;
    int m = (a + 11*h + 22*l) / 451;
    int t = h + l - 7*m + 114;
    int n = t / 31;
    int o = t % 31;
    return LocalDate.of(year, n, o+1);
}

In this implementation:

  • a is the Golden Number
  • b is the secular year
  • c is the vintage
  • d and e handle leap century adjustments
  • f and g relate to the proemptosis, an adjustment in the lunar equation to account for the Metonic’s cycle imperfection
  • h represents the epact
  • i and k assist in further leap-year adjustments
  • l represents the first Sunday of January
  • m is the final correcting term that allows us to compute Easter’s month and day

3.3. Conway Algorithm

A British mathematician named John Conway introduced a new original way to calculate Easter’s date in the second half of the 20th century. For this, he introduced the notion of pivotal days, a series of monthly dates that consistently occur on the same weekday, serving as fundamental reference points for calculating significant events.

Let’s code it:

LocalDate computeEasterDateWithConwayAlgorithm(int year) {
    int s = year / 100;
    int t = year % 100;
    int a = t / 4;
    int p = s % 4;
    int x = (9 - 2*p) % 7;
    int y = (x + t + a) % 7;
    int g = year % 19;
    int G = g + 1;
    int b = s / 4;
    int r = 8 * (s + 11) / 25;
    int C = -s + b + r;
    int d = (11*G + C) % 30;
    d = (d + 30) % 30;
    int h = (551 - 19*d + G) / 544;
    int e = (50 - d - h) % 7;
    int f = (e + y) % 7;
    int R = 57 - d - f - h;
        
    if (R <= 31) {
        return LocalDate.of(year, 3, R);
    }
    return LocalDate.of(year, 4, R-31);
}

More precisely, in this code:

  • s is the secular year, and t the vintage
  • a assists in determining leap years within a century
  • x is the secular pivotal day
  • y is the current year’s pivotal day
  • G denotes the Golden Number
  • b relates to metemptosis, a correction to the lunar equation to prevent Easter’s date from falling one day too late
  • r is the proemptosis
  • C is the secular correction
  • d determines the Paschal full moon’s day
  • h accounts for epact-related exceptions
  • e measures the deviation between the Paschal full moon and the pivotal day
  • lastly, f represents the day of the week of the Paschal full moon, allowing us the eventual calculation of Easter’s date

4. Conclusion

In this article, we understood why algorithms are needed to calculate Easter’s date and implemented the three most famous ones. Simplifications of the Gauss and Butcher-Meeus algorithms exist to calculate Easter’s date in the Julian calendar. However, this isn’t the end of the story for churches that still use the Julian calendar. Nearly all countries use the Gregorian calendar, so in the end, they must convert the date to this calendar.

The code backing this article is available on GitHub. Once you're logged in as a Baeldung Pro Member, start learning and coding on the project.
Baeldung Pro – NPI EA (cat = Baeldung)
announcement - icon

Baeldung Pro comes with both absolutely No-Ads as well as finally with Dark Mode, for a clean learning experience:

>> Explore a clean Baeldung

Once the early-adopter seats are all used, the price will go up and stay at $33/year.

eBook – HTTP Client – NPI EA (cat=HTTP Client-Side)
announcement - icon

The Apache HTTP Client is a very robust library, suitable for both simple and advanced use cases when testing HTTP endpoints. Check out our guide covering basic request and response handling, as well as security, cookies, timeouts, and more:

>> Download the eBook

eBook – Java Concurrency – NPI EA (cat=Java Concurrency)
announcement - icon

Handling concurrency in an application can be a tricky process with many potential pitfalls. A solid grasp of the fundamentals will go a long way to help minimize these issues.

Get started with understanding multi-threaded applications with our Java Concurrency guide:

>> Download the eBook

eBook – Java Streams – NPI EA (cat=Java Streams)
announcement - icon

Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.

But these can also be overused and fall into some common pitfalls.

To get a better understanding on how Streams work and how to combine them with other language features, check out our guide to Java Streams:

>> Join Pro and download the eBook

eBook – Persistence – NPI EA (cat=Persistence)
announcement - icon

Working on getting your persistence layer right with Spring?

Explore the eBook

Course – LS – NPI EA (cat=REST)

announcement - icon

Get started with Spring Boot and with core Spring, through the Learn Spring course:

>> CHECK OUT THE COURSE

Partner – Moderne – NPI EA (tag=Refactoring)
announcement - icon

Modern Java teams move fast — but codebases don’t always keep up. Frameworks change, dependencies drift, and tech debt builds until it starts to drag on delivery. OpenRewrite was built to fix that: an open-source refactoring engine that automates repetitive code changes while keeping developer intent intact.

The monthly training series, led by the creators and maintainers of OpenRewrite at Moderne, walks through real-world migrations and modernization patterns. Whether you’re new to recipes or ready to write your own, you’ll learn practical ways to refactor safely and at scale.

If you’ve ever wished refactoring felt as natural — and as fast — as writing code, this is a good place to start.

eBook Jackson – NPI EA – 3 (cat = Jackson)