Java Character isValidCodePoint() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
java.lang.Character

Definition

In Java, Character.isValidCodePoint(codePoint) returns true when the int is between Character.MIN_CODE_POINT (0) and Character.MAX_CODE_POINT (0x10FFFF), inclusive. Those are all the numbers Unicode can ever use.

It is a pure range check. It does not ask whether a character is assigned: unassigned code points and the surrogate range U+D800 to U+DFFF are still "valid" here. Its main job is protecting methods such as toChars(), which throw for anything outside the range.

A static method of java.lang.Character (Java 5+): call it on the class, as in Character.isValidCodePoint(...); you do not need a Character object. No import is needed, because java.lang is always available.

Syntax

Pass any int.

Java
Character.isValidCodePoint(0x41);       // true
Character.isValidCodePoint(0x10FFFF);   // true, the largest code point
Character.isValidCodePoint(0x110000);   // false
Character.isValidCodePoint(-1);         // false
CallWhat it does
if (Character.isValidCodePoint(cp)) ...Guard a conversion of untrusted input.
cp >= 0 && cp <= Character.MAX_CODE_POINTThe same check, written out.
Character.isValidCodePoint(Integer.parseInt(hex, 16))Validate a hex code typed by a user.

Only one overload exists, isValidCodePoint(int codePoint), added in Java 5.

Library declarations
Java
// java.lang.Character (since Java 5)
public static boolean isValidCodePoint(int codePoint)

public static final int MIN_CODE_POINT = 0x000000;
public static final int MAX_CODE_POINT = 0x10FFFF;

Parameters

ParameterDescription
codePoint (int)The number to check.

Return Value

Return ValueDescription
true0 to 0x10FFFF inclusive.
falseNegative, or greater than 0x10FFFF.

Compare with Similar Methods

Range checks for code points:

MethodHow it differs
isBmpCodePoint(cp)0 to 0xFFFF only (Java 7+).
isSupplementaryCodePoint(cp)0x10000 to 0x10FFFF only.
isDefined(cp)Assigned characters only.

Java Examples

Example 1 — Code Points at the Edges of the Range

Check zero, a letter, a surrogate, the largest code point, one past it, and a negative number.

Java
public class CharacterIsValidCodePointTable {
    public static void main(String[] args) {
        int[] values = {0, 'A', 0xD800, 0x10FFFF, 0x110000, -1};
        for (int v : values) {
            System.out.println(v + " valid=" + Character.isValidCodePoint(v));
        }
    }
}

How It Works

  1. Both ends are included. 0 and 1114111 (0x10FFFF) are the smallest and largest valid code points.
  2. Surrogates pass. 55296 (0xD800) is reserved for surrogate halves, but it is still inside the range, so the answer is true.
  3. Outside the range. 1114112 is one past the maximum, and -1 is negative; both are rejected.

Example 2 — Validate Hex Code Points Before Converting Them

Parse hex strings typed by a user, reject invalid ones, and convert the rest with toChars.

Java
public class CharacterIsValidCodePointParse {
    public static void main(String[] args) {
        String[] inputs = {"41", "1F600", "110000"};
        for (String hex : inputs) {
            int cp = Integer.parseInt(hex, 16);
            if (Character.isValidCodePoint(cp)) {
                char[] units = Character.toChars(cp);
                System.out.println(hex + ": ok, " + units.length + " char(s)");
            } else {
                System.out.println(hex + ": not a code point");
            }
        }
    }
}

How It Works

  1. Parse in base 16. Integer.parseInt(hex, 16) turns "1F600" into 128512 and "110000" into 1114112.
  2. Check before converting. Only valid values reach Character.toChars, so no IllegalArgumentException can occur.
  3. Report the size. units.length shows that U+0041 needs one char and U+1F600 needs two.

Example 3 — MIN_CODE_POINT, MAX_CODE_POINT, and What Happens Without a Check

Print the range constants, count the valid code points, then call toChars on an invalid value.

Java
public class CharacterIsValidCodePointRange {
    public static void main(String[] args) {
        System.out.println("MIN_CODE_POINT = " + Character.MIN_CODE_POINT);
        System.out.println("MAX_CODE_POINT = 0x" + Integer.toHexString(Character.MAX_CODE_POINT));
        System.out.println("valid values: " + (Character.MAX_CODE_POINT - Character.MIN_CODE_POINT + 1));
        int bad = Character.MAX_CODE_POINT + 1;
        System.out.println("isValidCodePoint(max + 1): " + Character.isValidCodePoint(bad));
        try {
            Character.toChars(bad);
        } catch (IllegalArgumentException e) {
            System.out.println("toChars(max + 1): IllegalArgumentException");
        }
    }
}

How It Works

  1. Named constants. Character.MIN_CODE_POINT and MAX_CODE_POINT are clearer than writing 0 and 0x10FFFF by hand.
  2. 17 planes. 0x10FFFF + 1 = 1114112 = 17 * 65536, the number of possible code points.
  3. No check, an exception. toChars rejects max + 1 with IllegalArgumentException, which isValidCodePoint would have predicted.

Frequently Asked Questions

0 to 0x10FFFF (1,114,111), which gives 1,114,112 possible values. Character.MAX_CODE_POINT holds the upper limit.
Yes, for isValidCodePoint. U+D800 to U+DFFF are inside the range, even though they are not characters on their own.
No. Most valid code points are unassigned. Use isDefined to check whether a character is assigned.
Character.toChars, Character.toString(int) (Java 11+), and StringBuilder.appendCodePoint throw IllegalArgumentException.
No. It returns false for any int outside the range.

Next: isWhitespace()

Check whether a character is whitespace by Java's rules (spaces, tabs, line breaks).

isWhitespace() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

11 people found this page helpful