char
Java's primitive type holding one UTF-16 code unit, which covers most but not all single characters.
In more detail
Characters outside the basic range, such as many emoji, take two chars in a Java string. So a char is fine for a simple symbol but is not a complete model of a human-visible character. char literals use single quotes.
Example
char initial = 'A';Related terms
- UTF-16 — A Unicode encoding that stores each character as one or two 16-bit code units, used in memory by Java and JavaScript strings and by Windows.
- string — A sequence of characters, that is, a piece of text.
- primitive type — A basic built-in type, such as a whole number or true-or-false, whose values are held directly rather than as objects.
Taught in
- Primitive And Reference Types — Modern Java: Virtual Threads & High-Throughput Services
- Fifty Items, Five Traps — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Promotion, Wrappers And The Math API — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Strings, StringBuilder And Text Blocks — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Switch, Loops And Labels — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Values And Flow — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Object-Oriented Java — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Lambdas And Streams — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Console And File I/O With Streams — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: I/O And Localization — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep