In Java, Character.getName(codePoint) returns the official Unicode name of a character as an uppercase String. For 'A' it returns "LATIN CAPITAL LETTER A"; for U+1F600 it returns "GRINNING FACE".
Names are a safe way to describe characters in logs and error messages: they are plain ASCII, so they print correctly on any console, even when the character itself would not.
A static method of java.lang.Character (Java 7+): call it on the class, as in Character.getName(...); you do not need a Character object. No import is needed, because java.lang is always available.
Unicode version.
The answer comes from the Unicode Character Database built into your JDK, and each Java release follows a specific Unicode version (Java 8, for example, uses Unicode 6.2). The characters used on this page have had the same properties for many Unicode versions, so the examples print the same result on any current JDK.
Syntax
Pass an int code point; a char is widened automatically.
Java
Character.getName('A'); // "LATIN CAPITAL LETTER A"
Character.getName(0x1F600); // "GRINNING FACE"
Character.getName(0x10FFFF); // null, nothing is assigned there
Character.getName(0x110000); // throws IllegalArgumentException
Call
What it does
Character.getName(c)
Name of a char.
Character.getName(s.codePointAt(i))
Name of the character at index i, emoji included.
name != null ? name : "unassigned"
Handle unassigned code points.
One overload, getName(int codePoint), added in Java 7. The reverse lookup, codePointOf(name), was added in Java 9.
Library declarations
Java
// java.lang.Character (since Java 7)
public static String getName(int codePoint)
Print the names of ASCII chars, an accented letter, and an emoji. The output is plain ASCII.
Java
public class CharacterGetNameBasic {
public static void main(String[] args) {
int[] cps = {'A', 'a', '7', ' ', '$', 0x00E9, 0x1F600};
for (int cp : cps) {
System.out.println("U+" + Integer.toHexString(cp) + " " + Character.getName(cp));
}
}
}
Output
U+41 LATIN CAPITAL LETTER A
U+61 LATIN SMALL LETTER A
U+37 DIGIT SEVEN
U+20 SPACE
U+24 DOLLAR SIGN
U+e9 LATIN SMALL LETTER E WITH ACUTE
U+1f600 GRINNING FACE
How It Works
chars in an int array. Char literals such as 'A' widen to their codes, so the array mixes chars and hex code points freely.
Descriptive names. The accented letter is LATIN SMALL LETTER E WITH ACUTE, which describes it exactly without printing it.
Emoji have names too. U+1F600 is GRINNING FACE, even though the character needs two chars in a String.
Example 2 — null for Unassigned, an Exception for Invalid
Ask for the name of a noncharacter, then for two values that are not code points at all.
Java
public class CharacterGetNameMissing {
public static void main(String[] args) {
String name = Character.getName(0x10FFFF);
System.out.println("U+10FFFF: " + (name == null ? "null (unassigned)" : name));
int[] bad = {0x110000, -1};
for (int cp : bad) {
try {
Character.getName(cp);
} catch (IllegalArgumentException e) {
System.out.println(cp + ": IllegalArgumentException");
}
}
}
}
A valid but empty slot. U+10FFFF is a permanent noncharacter: a legal code point with no character, so the result is null.
Check before use. Calling a method on the null result would throw, so the code tests name == null first.
Not a code point. 0x110000 (1114112) is one past the maximum and -1 is negative; both throw IllegalArgumentException.
Example 3 — Describe Every Character of a String by Name
Walk a string by code point and print each name, including one for an emoji.
Java
public class CharacterGetNameDescribe {
public static void main(String[] args) {
String s = "x=\uD83D\uDC4D";
int i = 0;
while (i < s.length()) {
int cp = s.codePointAt(i);
System.out.println(i + ": " + Character.getName(cp));
i += Character.charCount(cp);
}
}
}
Output
0: LATIN SMALL LETTER X
1: EQUALS SIGN
2: THUMBS UP SIGN
How It Works
One name per character. The loop asks for the name of each code point, not each char, so the emoji gets one line.
Indexes jump. After the thumbs-up at index 2, charCount adds 2 and the loop ends at length 4.
Readable logs. Printing names instead of the characters keeps the output ASCII-only and makes invisible or look-alike chars obvious.
Frequently Asked Questions
The Unicode name of the code point in uppercase, for example "LATIN CAPITAL LETTER A", or null if the code point is unassigned.
Java 7.
It throws IllegalArgumentException for values below 0 or above 0x10FFFF.
Yes, on Java 9 and newer with Character.codePointOf(name).
Many CJK ideographs have no individual name in the Unicode data, so Java combines the block name and the code point in hex.