1. Primitive data types

0.0(0)
studied byStudied by 0 people
GameKnowt Play
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/22

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

23 Terms

1
New cards

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.

2
New cards

Why are primitive types not objects in Java?

For efficiency—they’re simple binary values, not objects, allowing fast, compact storage.

3
New cards

How many primitive types does Java have and what are they?

Eight: boolean, byte, char, short, int, long, float, double.

4
New cards

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.

5
New cards

List Java’s integer primitive types in order of increasing width.

byte (8-bit), short (16-bit), int (32-bit), long (64-bit).

6
New cards

What is the range of the Java byte type?

–128 to 127.

7
New cards

What is the range of the Java short type?

–32,768 to 32,767.

8
New cards

What is the range of the Java int type?

–2,147,483,648 to 2,147,483,647.

9
New cards

What is the range of the Java long type?

–9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.

10
New cards

Does Java support unsigned integer types?

No; Java only supports signed integers.

11
New cards

Which integer type is most commonly used in Java, and why?

int, because it’s efficient for loops, array indexing, and general-purpose math.

12
New cards

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).

13
New cards

What are Java’s floating-point primitive types and their sizes?

float (32-bit single precision) and double (64-bit double precision).

14
New cards

Which floating-point type is most commonly used in Java?

double, since math library methods like Math.sqrt() return and work in double precision.

15
New cards

How are Java characters represented and what is the width of char?

As Unicode, an unsigned 16-bit type with values 0–65,535.

16
New cards

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);.

17
New cards

Can you perform arithmetic on char variables in Java?

Yes—char can be incremented or assigned integer values corresponding to Unicode code points.

18
New cards

What subset of Unicode does Java’s char cover for ASCII?

0–127; standard ASCII characters map directly to Unicode 0–127.

19
New cards

Which primitive type represents true/false values in Java?

boolean.

20
New cards

What are the two boolean values in Java?

true and false.

21
New cards

How can a boolean variable control an if statement in Java?

You can write if (b) directly—no need to compare b == true.

22
New cards

What type of value do relational operators (e.g., >, <) produce in Java?

A boolean.

23
New cards

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.