Boolean, char and Unicode
What you will learn
A boolean stores true or false. A char stores one UTF-16 code unit, an unsigned 16-bit value. These types serve different purposes: decisions versus units of text representation.
public class Main { public static void main(String[] args) { boolean available = true; char section = 'B'; System.out.println(available); System.out.println(section); }}Expected output:
trueBThe flag and the code unit print using their distinct representations.
How it works
Use boolean open = true; and char grade = 'A';. A character literal uses single quotes, while text uses double quotes. Java strings use UTF-16 code-unit indexing; supplementary Unicode code points may occupy two char values. Boolean is not a numeric type: Java does not implicitly convert 0 or 1 to false or true.
public class Main { public static void main(String[] args) { char letter = 'Ω'; System.out.println(letter); }}Expected output:
ΩThis code point fits in one UTF-16 code unit; UTF-8 output encoding is selected in the fixture.
Common mistakes
Do not assume every visible character fits in one char. A supplementary code point such as U+1F600 needs two UTF-16 code units; combining sequences can also form one visible character from multiple code points.
Try it yourself
Declare an open/closed flag and a single-letter room code. Print both, then switch the flag to false.
These are local Java practice tasks, not automatically graded ByteMind exercises. Use a patched JDK; no network or third-party dependency is needed.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Boolean, char and Unicode — knowledge check
Check your understanding of boolean, char and unicode.
Which values can boolean hold?
What does a Java char represent?