In Java, Character.isUnicodeIdentifierPart(ch) returns true when the character may appear after the first position of a Unicode identifier: letters, digits, connector punctuation such as '_', letter numbers, combining marks, non-spacing marks, and ignorable characters.
Compared with isJavaIdentifierPart(), the main difference is currency symbols: '$' is allowed in a Java name but not in a Unicode identifier.
A static method of java.lang.Character (Java 1.1+): call it on the class, as in Character.isUnicodeIdentifierPart(...); you do not need a Character object. No import is needed, because java.lang is always available. The int codePoint overload was added in Java 5.
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.
Two validators. Each helper checks the first char with a start method and the rest with the matching part method.
The dollar sign.price$ is a legal Java variable name, but under Unicode rules '$' is not an identifier part.
Common ground. Names built from letters, digits, and underscores after a letter, such as user_name and x2, pass both.
Example 3 — Validate a Name That Contains a Supplementary Letter
Walk the string by code point so a letter above U+FFFF is tested as one character.
Java
public class CharacterIsUnicodeIdentifierPartCodePoints {
static boolean allParts(String s) {
int i = 0;
while (i < s.length()) {
int cp = s.codePointAt(i);
if (!Character.isUnicodeIdentifierPart(cp)) return false;
i += Character.charCount(cp);
}
return true;
}
public static void main(String[] args) {
System.out.println("with a math letter: " + allParts("a\uD835\uDC00_1"));
System.out.println("with an emoji: " + allParts("a\uD83D\uDE00"));
System.out.println("lone char 0xd835: " + Character.isUnicodeIdentifierPart('\uD835'));
}
}
Output
with a math letter: true
with an emoji: false
lone char 0xd835: false
How It Works
One code point at a time.codePointAt joins the pair 0xD835 0xDC00 into U+1D400, and charCount moves past both chars.
The letter passes. U+1D400 is a letter, so the whole name is accepted; the emoji is a symbol, so the second name is not.
Why code points matter. Testing the high surrogate 0xD835 by itself returns false, so a char-by-char scan would wrongly reject the first name.
Frequently Asked Questions
Letters, digits, connector punctuation such as _, letter numbers, combining and non-spacing marks, and identifier-ignorable characters.
The Unicode identifier rules do not include currency symbols. Java adds them as an extension, which isJavaIdentifierPart reflects.
Yes, after the first position. It is connector punctuation, which isUnicodeIdentifierPart accepts.
A supplementary letter is two chars, and each surrogate alone returns false. The int overload tests the whole character.
Yes. Identifier-ignorable chars such as U+200B pass, so strip them with isIdentifierIgnorable if names are compared as Strings.