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 – Black Friday 2026 – NPI EA – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – before_post_content
announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

1. Overview

In this short tutorial, we’ll see how to get the ASCII value of a character and convert an ASCII value to its character equivalent in Java.

2. Get the ASCII Value of a Character

To get the ASCII value of a character in Java, we can use explicit casting. Additionally, we can get the ASCII value of a character in a string.

2.1. Use Casting

To get the ASCII value of a character, we can simply cast our char as an int:

char c = 'a';
System.out.println((int) c);

And here is the output:

97

Remember that char in Java can be a Unicode character. So our character must be an ASCII character to be able to get its correct ASCII numeric value.

2.2. Character Inside a String

If our char is in a String, we can use the charAt() method to retrieve it:

String str = "abc";
char c = str.charAt(0);
System.out.println((int) c);

3. Getting the Character of an ASCII Value

Simply put, we can convert an ASCII value to its equivalent char by casting:

int value = 65;
char c = (char) value;
System.out.println(c);

Here’s the output of the code:

A

Notably, we need to supply an integer within the ASCII value range (0–127) to get the corresponding ASCII character. Any integer outside the ASCII range won’t return null, but a character representation of that integer value in the Unicode character set.

4. Conclusion

In this article, we learned how to get the ASCII value of a character in Java. Also, we saw how to get the character of an ASCII value.

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.

Course – Black Friday 2026 – NPI EA – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW

Course – Black Friday 2026 – NPI – main – after_post_content

announcement - icon

Yes, we're now running our Black Friday Sale. All Courses are 33% off until 4th December, 2026 at 17:00 Romania time:

>> EXPLORE ACCESS NOW