Primitive Data Types in Java
Primitive datatypes in Java are the most basic and fundamental types of data that represent simple values such as numbers, characters, or logical values. They are predefined by the language, not objects, and store values directly in memory.
Java provides 8 primitive datatypes, which cover different categories of values. These types are fast and memory-efficient because they work directly with the CPU and do not require object overhead.
- Integer Types → byte, short, int, long
- Floating-point Types → float, double
- Character Type → char
- Logical Type → boolean
Each primitive type has a fixed size, range, and default value, which makes Java a strongly typed language.
Primitive Data Types Table
| Datatype | Size | Range | Default Value | Example |
|---|---|---|---|---|
| byte | 1 byte | -128 to 127 | 0 | byte age = 25; |
| short | 2 bytes | -32,768 to 32,767 | 0 | short temp = -200; |
| int | 4 bytes | -2,147,483,648 to 2,147,483,647 | 0 | int salary = 50000; |
| long | 8 bytes | Very large (±9 quintillion) | 0L | long population = 7800000000L; |
| float | 4 bytes | ~6–7 decimal digits precision | 0.0f | float pi = 3.14f; |
| double | 8 bytes | ~15–16 decimal digits precision | 0.0d | double rate = 19.87654321; |
| char | 2 bytes | '\u0000' (0) to '\uffff' (65,535) | '\u0000' | char grade = 'A'; |
| boolean | 1 bit (JVM uses 1 byte internally) | true or false | false | boolean isJavaFun = true; |
Summary
Primitive datatypes are the simplest and most efficient way to store data in Java. Each datatype has a fixed size, range, default value, and storage format (base 2, IEEE-754, UTF-16, etc.), making Java a strongly typed and portable language.