Primitive vs Reference Types
Understand the fundamental difference between primitive types and reference types in Java.
Primitive vs Reference Types
Java has two fundamental categories of data types: primitive types and reference types. Understanding the difference is crucial to writing correct, efficient Java code.
The Eight Primitive Types
Java has exactly eight primitive types:
byte(8-bit integer)short(16-bit integer)int(32-bit integer)long(64-bit integer)float(32-bit decimal)double(64-bit decimal)char(16-bit Unicode character)boolean(true/false)
Primitives hold the value directly in memory — no object overhead.
int age = 25;
double price = 19.99;
boolean active = true;
char grade = 'A';
long population = 8_000_000_000L;
System.out.println(age); // 25
System.out.println(price); // 19.99
System.out.println(active); // trueAll lessons in this course
- Primitive vs Reference Types
- Widening and Narrowing Conversions
- The instanceof Operator
- Type Casting in Practice