1/22
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What are the two general categories of built-in data types in Java?
Object-oriented types (defined by classes) and non-object-oriented primitive types.
Why are primitive types not objects in Java?
For efficiency—they’re simple binary values, not objects, allowing fast, compact storage.
How many primitive types does Java have and what are they?
Eight: boolean, byte, char, short, int, long, float, double.
Why does Java strictly specify ranges and behavior for its primitive types?
To ensure portability across all JVM implementations so code behaves identically on every platform.
List Java’s integer primitive types in order of increasing width.
byte (8-bit), short (16-bit), int (32-bit), long (64-bit).
What is the range of the Java byte type?
–128 to 127.
What is the range of the Java short type?
–32,768 to 32,767.
What is the range of the Java int type?
–2,147,483,648 to 2,147,483,647.
What is the range of the Java long type?
–9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
Does Java support unsigned integer types?
No; Java only supports signed integers.
Which integer type is most commonly used in Java, and why?
int, because it’s efficient for loops, array indexing, and general-purpose math.
When should you use long instead of int in Java?
When you need to store values outside the 32-bit int range (e.g., calculating cubic inches in a mile).
What are Java’s floating-point primitive types and their sizes?
float (32-bit single precision) and double (64-bit double precision).
Which floating-point type is most commonly used in Java?
double, since math library methods like Math.sqrt() return and work in double precision.
How are Java characters represented and what is the width of char?
As Unicode, an unsigned 16-bit type with values 0–65,535.
How do you assign a character literal in Java and print it?
Use single quotes (e.g., char ch = 'X';) and System.out.println(ch);.
Can you perform arithmetic on char variables in Java?
Yes—char can be incremented or assigned integer values corresponding to Unicode code points.
What subset of Unicode does Java’s char cover for ASCII?
0–127; standard ASCII characters map directly to Unicode 0–127.
Which primitive type represents true/false values in Java?
boolean.
What are the two boolean values in Java?
true and false.
How can a boolean variable control an if statement in Java?
You can write if (b) directly—no need to compare b == true.
What type of value do relational operators (e.g., >, <) produce in Java?
A boolean.
Why did Java choose Unicode for its char type despite inefficiency for some languages?
To support global character sets and ensure worldwide portability of Java programs.