Java — What is the numerical range of the char data type?
Java Programming
Objects and Collections
Difficulty: Easy
Choose an option
-
A0 to 32767
-
B0 to 65535
-
C-256 to 255
-
D-32768 to 32767
Answer
Correct Answer: 0 to 65535
Explanation
Introduction / Context:The char type in Java is a 16-bit unsigned integer representing a Unicode character. Unlike C/C++, Java chars are not signed and cover a wide range of Unicode code points.
Given Data / Assumptions:
- char size: 16 bits (2 bytes).
- Unsigned, not negative.
- Stores Unicode characters.
Concept / Approach:The range of a 16-bit unsigned integer is 0 to (2^16 - 1) = 65535.
Step-by-Step Solution:
Minimum: 0 → represents null character '\u0000'.Maximum: 65535 → corresponds to '\uffff'.Why Other Options Are Wrong:
- 32767 is max for signed 16-bit, but char is unsigned.
- -256 to 255 describes byte range incorrectly.
- -32768 to 32767 describes signed short, not char.
Final Answer:0 to 65535