liveBook · Manning

Code point

As explained in 100 Java Mistakes and How to Avoid Them

A Unicode code point is a numeric value identifying an abstract character or character-related symbol in the Unicode character set.

A Unicode code point identifies an abstract character or character-related symbol. Java’s char stores a UTF-16 code unit, not necessarily one displayed character: code points above 0xFFFF use surrogate pairs outside the Basic Multilingual Plane. section 6.1

The fixed-width splitting mistake

Splitting a string with substring() by char positions can cut a surrogate pair or separate a combining character. An emoji such as code point 0x1F601 uses two chars; a waving-hand symbol with a skin-tone modifier can use four. The result may display replacement characters or lose the modifier. section 6.1

Avoid treating char positions as displayed-character positions:

  • Use codePointAt() when character classification must handle supplementary code points. section 6.1
  • Use codePoints() when processing or rebuilding text by code point. section 6.1
  • Use BreakIterator for boundaries that should respect character-level text segmentation. section 6.1
String part = string.codePoints().skip(rowNumber * rowLength)
       .limit(rowLength)
       .collect(StringBuilder::new,
                StringBuilder::appendCodePoint,
                StringBuilder::append)
       .toString();

Build fixed-size chunks by streaming code points and appending each complete code point rather than slicing UTF-16 units. section 6.1

How 100 Java Mistakes and How to Avoid Them covers it

How deep it goes
Explains surrogate pairs, combining characters, failure effects, and Java alternatives, but does not fully define grapheme segmentation.
Examples
Uses emoji, skin-tone modifiers, fixed-row string splitting, digit checks, code-point streams, and BreakIterator.
What it assumes
Assumes Java String and char familiarity while teaching why char values do not always represent complete characters.
What you can do after
Apply it via Java codePointAt(), codePoints(), and BreakIterator when processing Unicode text safely.
How it connects
Connects Unicode code points with Java char, UTF-16 surrogate pairs, the Basic Multilingual Plane, combining characters, and String.

Also explained in

Compare how 6 books explain code point →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of 100 Java Mistakes and How to Avoid Them. The section links point to the parts of the book it draws on.