Java Zero to All All questionsPractise free
Interview questions › Java Foundations — Zero to Basics › Variables, Data Types & Operators

Why is char a numeric type in Java, and what breaks when you treat a String as a sequence of chars for non-Latin text?

Level III · MidVariables, Data Types & Operators
Short answer

char is an unsigned 16-bit UTF-16 code unit, so it participates in arithmetic and 'A' + 1 yields 66.

Explanation

The trap is that characters outside the Basic Multilingual Plane (emoji, many CJK extensions) are encoded as surrogate pairs spanning two chars, so str.length() and charAt() count code units, not code points. For correct counting or iteration use codePointCount, codePoints(), or String methods that are code-point aware.

Common mistakes
  • Treating String.length() as the number of visible characters for emoji or non-BMP text.
  • Splitting strings by char and breaking surrogate pairs; use code points.

Can you say this out loud in two minutes? Drill it in a timed mock interview, with flashcards and runnable code for Variables, Data Types & Operators.

Practise free

More on Variables, Data Types & Operators