1 byte = 8 bits
🔹 1. By Data Type
These define what kind of value the variable can hold.
Easy Way to
Type Example Range/Size
Remember
Think small pocket
byte byte b = 100; -128 to 127 (1 byte)
(only 1 byte space).
Easy Way to
Type Example Range/Size
Remember
short s = "Short is 2 shorts = 2
short 30000; -32,768 to 32,767 (2 bytes)
bytes".
Most common
int x = -2,147,483,648 to 2,147,483,647 (4
int 100000; number type (default
bytes)
for whole numbers).
long l = Huge! -9,22,33,72,036,854,775,808 to "Long journey needs
long 9999999999L; +9,22,33,72,036,854,775,807 (8 bytes) more space".
float f = "Float like water
float 3.14f; ~6–7 decimal digits (4 bytes)
(decimal but light)".
"Double precision =
double d =
double 3.141592653; ~15–16 decimal digits (8 bytes) more accurate
decimals".
Single Unicode character (2 bytes in Think of character =
char char c = 'A';
Java) alphabet.
boolean flag = true or false (1 bit, but JVM uses 1 "Boolean = Binary
boolean true;
byte) (Yes/No, 1/0)".
👉 Memory Trick (in size order):
byte < short < int < long (all integers)
float < double (decimals)
🔹 2. By Scope / Lifetime
These define where and how long a variable exists.
Type Example Scope & Lifetime Memory Trick
Local Defined inside a method, Exists only while "Local = lives in local
Variable e.g. int x = 5; method runs area only".
Instance Defined in a class but Each object gets its "Instance = for each
Variable outside methods own copy object instance".
Static Shared across all "Static = stays same for
Declared with static
Variable objects of class all".
🔹 3. By Value Type
Primitive Variables → Directly store values (like int, float, etc.).
Reference Variables → Store address of objects (like String, Array, custom
classes).
👉 Trick:
Primitive = Actual value
Reference = Remote control (points to object).
🧠 Memory Technique to Remember Ranges
Here’s a simple shortcut:
1. Byte → 1 byte → range = 2⁸ = 256 values → -128 to 127
2. Short → 2 bytes → 2¹⁶ = 65,536 values → -32,768 to 32,767
3. Int → 4 bytes → 2³² values → -2B to +2B
4. Long → 8 bytes → 2⁶⁴ values → very huge
👉 Rule:
Range = -2^(n-1) to (2^(n-1) - 1) where n = number of bits.