8 Primitive Data Types in Java with Sizes
Fast recall
Quick revision
Core answer
byte (8-bit), short (16-bit), int (32-bit), long (64-bit), float (32-bit IEEE 754), double (64-bit IEEE 754), char (16-bit UTF-16 code unit), and boolean (true or false; its storage size is not specified by the Java language). Primitive values are not objects and cannot be null.Basic Java knowledge and whether the candidate has actually used Java or just read about it
Confusing float/double sizes or forgetting that char is 2 bytes in Java (not 1 like C)
Mention default values (int → 0, boolean → false, char → \u0000) and that primitives can't be null
Interview-ready guide
Interview answer
Java has eight primitives. The integer types are byte, short, int, and long at 8, 16, 32, and 64 bits. Float and double are 32-bit and 64-bit IEEE 754 floating-point types. Char is a 16-bit UTF-16 code unit, and boolean represents true or false.
The important qualification is that Java does not specify a storage size for boolean. Also, one char is not always one complete Unicode character; an emoji may need a surrogate pair. Primitive values cannot be null, and local variables—unlike fields and array elements—must be assigned before they are read.
8 Primitive Data Types in Java with Sizes
Direct Answer
Java has eight primitive types: byte (8-bit), short (16-bit), int (32-bit), long (64-bit), float (32-bit IEEE 754), double (64-bit IEEE 754), char (16-bit UTF-16 code unit), and boolean (true or false; its storage size is not specified by the Java language). Primitive values are not objects and cannot be null.
Code Example
public class PrimitivesDemo {
public static void main(String[] args) {
byte age = 25; // small whole number
short year = 2024; // medium whole number
int score = 95; // default integer
long userId = 9876543210L; // large number — needs L
float rating = 4.5f; // decimal — needs f
double price = 9.99; // default decimal
char grade = 'A'; // single character, 2 bytes
boolean isPassed = true; // true or false only
System.out.println("Score: " + score + ", Grade: " + grade);
System.out.println("User " + userId + " paid " + price);
}
}
// Output:
// Score: 95, Grade: A
// User 9876543210 paid 9.99
Every variable here is a primitive — no new keyword, no objects, just values stored directly.
Common Mistakes & Pitfalls
- Thinking
charis 1 byte like in C: Java'scharis 2 bytes because it stores a UTF-16 Unicode code unit, not an ASCII byte — anyone coming from C or C++ gets this wrong. - Mixing up
floatanddouble:floatis 4 bytes (~7 significant digits),doubleis 8 bytes (~15). Reaching forfloatto "save space" on a single value buys nothing and quietly loses precision —doubleis the default for a reason. - Forgetting the literal suffix:
long big = 10000000000;does not compile — the literal is read as anintand overflows. Write10000000000L. Same trap withfloat f = 3.14;, which needs3.14f. - Assuming a primitive can be
null:int x = null;is a compile error. Primitives always hold a value — switch to the wrapper (Integer,Double) only when "absent" is a state you genuinely need to represent.
Check your understanding
Answer these without looking back at the article.
- What is the difference between int and Integer in Java?
- When would you use long instead of int?
- What are the default values of primitive types in Java?
Looking for a structured roadmap?
Every module on this page is also part of the full Java backend interview track.