Module: | Core Architecture, Basics & Control Flow
Q9: Consider the following statements regarding Java's primitive data types:
1. Java has eight primitive data types, of which 'boolean' explicitly has a precisely defined and standardized memory size of 1 bit across all JVM implementations.
2. The 'char' data type in Java occupies 16 bits in memory because it utilizes the Unicode encoding system to represent a vast array of global characters.
3. The 'byte' primitive data type is a signed two's complement integer that can store numerical values ranging strictly from -128 to 127.
Which of the above statements is/are correct?
2. The 'char' data type in Java occupies 16 bits in memory because it utilizes the Unicode encoding system to represent a vast array of global characters.
3. The 'byte' primitive data type is a signed two's complement integer that can store numerical values ranging strictly from -128 to 127.
Which of the above statements is/are correct?
✅ Correct Answer: B
🎯 Quick Answer:
The correct combination is 2 and 3. Statement 1 is incorrect because the Java Virtual Machine specification does not precisely define the memory size of a boolean; while it represents 1 bit of information, JVMs often pad it to a full byte (8 bits) for addressability purposes.Structural Breakdown: The eight primitives are divided into four categories: integers (byte, short, int, long), floating-point (float, double), character (char), and boolean.
Historical/Related Context: Unlike C or C++, where the size of an 'int' might vary depending on the underlying 16-bit or 32-bit hardware processor, Java's creators strictly mandated fixed sizes for all numeric primitives (e.g., int is always 32 bits). The char type was expanded to 16 bits to support the Unicode standard, moving beyond the 8-bit ASCII limitations of older languages.
Causal Reasoning: The fixed memory architecture guarantees cross-platform consistency.
The byte type is restricted to -128 to 127 because it is exactly 8 bits long, and utilizing signed two's complement binary mathematics, the highest positive value an 8-bit signed integer can represent is 2^7 - 1.