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

Java 21 introduced a new set of methods in the java.lang.Character class to provide better support for emojis. These methods allow us to easily check if a character is an emoji and to check the properties and characteristics of the emoji characters.

In this tutorial, we’ll explore the newly added methods and walk through the key concepts related to emoji handling in Java 21.

2. Character API Updates

Java 21 introduced six new methods in the java.lang.Character class related to emoji handling. All of the new methods are static, take an int representing the Unicode code point of a character as a parameter, and return a boolean response.

A Unicode code point is a unique numeric value assigned to each character in the Unicode standard. It represents a specific character across different platforms and languages. For example, the code point U+0041 represents the letter “A” which is 0x0041 in the hexadecimal form.

The Unicode Consortium, a non-profit corporation, maintains and develops the Unicode standard and provides a full list of emojis and their corresponding Unicode code points.

Now, let’s take a closer look at each of these new emoji-related methods.

2.1. isEmoji()

The isEmoji(int codePoint) method is the most basic of the new emoji methods. It takes an int value representing a character’s Unicode code point and returns a boolean indicating whether the character is an emoji or not.

Let’s take a look at its usage:

String messageWithEmoji = "Hello Java 21! 😄";
String messageWithoutEmoji = "Hello Java!";

assertTrue(messageWithEmoji.codePoints().anyMatch(Character::isEmoji));
assertFalse(messageWithoutEmoji.codePoints().anyMatch(Character::isEmoji));

2.2. isEmojiPresentation()

The isEmojiPresentation(int codePoint) method determines whether a character should render as an emoji or not. Certain characters, like digits (0-9) and currency symbols ($ or €), can be rendered as either an emoji or a text character depending on the context.

Here’s a code snippet that demonstrates the usage of this method:

String emojiPresentationMessage = "Hello Java 21! 🔥😄";
String nonEmojiPresentationMessage = "Hello Java 21!";

assertTrue(emojiPresentationMessage.codePoints().anyMatch(Character::isEmojiPresentation));
assertFalse(nonEmojiPresentationMessage.codePoints().anyMatch(Character::isEmojiPresentation));

2.3. isEmojiModifier()

The isEmojiModifier(int codePoint) method checks if a character is an emoji modifier. Emoji modifiers are characters that can modify the appearance of an existing emoji, such as applying skin tone variations.

Let’s see how we can use this method to detect emoji modifiers:

assertTrue(Character.isEmojiModifier(0x1F3FB)); // light skin tone
assertTrue(Character.isEmojiModifier(0x1F3FD)); // medium skin tone
assertTrue(Character.isEmojiModifier(0x1F3FF)); // dark skin tone

In this test, we use the hexadecimal form of Unicode code points, e.g., 0x1F3FB, instead of the actual emoji characters because emoji modifiers don’t typically render as standalone emojis and lack visual distinction.

2.4. isEmojiModifierBase()

The isEmojiModifierBase(int codePoint) method determines whether an emoji modifier can modify a given character. This method helps to identify the emojis that support modifications, as not all emojis have this capability.

Let’s look at some examples to understand this better:

assertTrue(Character.isEmojiModifierBase(Character.codePointAt("👍", 0)));
assertTrue(Character.isEmojiModifierBase(Character.codePointAt("👶", 0)));
    
assertFalse(Character.isEmojiModifierBase(Character.codePointAt("🍕", 0)));

We see that the thumbs up emoji “👍” and the baby emoji “👶” are valid emoji modifiers bases, and can be used to express diversity by applying skin tone variations to change their appearance.

On the other hand, the pizza emoji “🍕” does not qualify as a valid emoji modifier base, since it’s a standalone emoji that represents an object rather than a character or symbol that can have its appearance modified.

2.5. isEmojiComponent()

The isEmojiComponent(int codePoint) method checks if a character can be used as a component to create a new emoji character. These characters usually combine with other characters to form new emojis, rather than appearing as standalone emojis.

For example, the Zero Width Joiner (ZWJ) character is a non-printing character that indicates to the rendering system that the adjacent characters should be displayed as a single emoji. By combining the emojis of a man “👨” (0x1F468) and a rocket “🚀” (0x1F680) using the zero width joiner character (0x200D), we can create a new emoji of an astronaut “👨‍🚀”. We can use a Unicode code converter site to test this out with the input: 0x1F4680x200D0x1F680.

The skin tone characters are also emoji components. We can combine the dark skin tone character (0x1F3FF) with a waving hand emoji “👋” (0x1F44B) to create a waving hand with dark skin tone “👋🏿” (0x1F44B0x1F3FF). Since we’re modifying the appearance of an existing emoji instead of creating a new one, we don’t need to use a ZWJ character for skin tone changes.

Let’s take a look at its usage and detect emoji components in our code:

assertTrue(Character.isEmojiComponent(0x200D)); // Zero width joiner
assertTrue(Character.isEmojiComponent(0x1F3FD)); // medium skin tone

2.6. isExtendedPictographic()

The isExtendedPictographic(int codePoint) method checks if a character is part of the broader category of pictographic symbols, which includes not only traditional emojis but also other symbols that are often rendered by text processing systems differently.

Objects, animals, and other graphical symbols have the extended pictographic property. While not always considered typical emojis, they need to be recognised and processed as part of the emoji set to ensure proper display.

Here’s an example that demonstrates the usage of this method:

assertTrue(Character.isExtendedPictographic(Character.codePointAt("☀️", 0)));  // Sun with rays
assertTrue(Character.isExtendedPictographic(Character.codePointAt("✔️", 0)));  // Checkmark

Both of the above code points return false if passed to the isEmojiPresentation() method, as they’re part of the broader Extended Pictographic category but don’t have the Emoji Presentation property.

3. Emoji Support in Regular Expressions

In addition to the new emoji methods, Java 21 also introduced emoji support in regular expressions. We can now use the \p{IsXXXX} construct to match characters based on their emoji properties.

Let’s take an example to search for any emoji character in a string using regular expressions:

String messageWithEmoji = "Hello Java 21! 😄";
Matcher isEmojiMatcher = Pattern.compile("\\p{IsEmoji}").matcher(messageWithEmoji);
    
assertTrue(isEmojiMatcher.find());

String messageWithoutEmoji = "Hello Java!";
isEmojiMatcher = Pattern.compile("\\p{IsEmoji}").matcher(messageWithoutEmoji);
    
assertFalse(isEmojiMatcher.find());

Similarly, we can use the other emoji constructs in our regular expressions:

  • IsEmoji_Presentation
  • IsEmoji_Modifier
  • IsEmoji_Modifier_Base
  • IsEmoji_Component
  • IsExtended_Pictographic

It’s important to note that the regex property constructs use the snakecase format to reference the methods. This is different from the lower camelcase format that the static methods in the Character class use.

These regular expression constructs provide a clean and easy way to search for and manipulate emoji characters in strings.

4. Conclusion

In this article, we explored the new emoji-related methods introduced in Java 21’s Character class. We understood the behaviour of these static methods by looking at various examples.

We’ve also discussed the newly added emoji support in regular expressions to search for emoji characters and their properties by using the Pattern class.

These new features can help us when we’re building a chat application, a social media platform, or any other type of application that uses emojis.

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)