Primitive Data Types
Java has 8 primitive data types that serve as the building blocks for all data manipulation. Understanding these types — their sizes, ranges, and uses — is essential for writing efficient Java programs. This is a foundational concept in enterprise application development that professional developers rely on daily. The explanations below are written to be beginner-friendly while covering the depth and nuance that comes from real-world Java experience. Take your time with each section and practice the examples
40 min•By Priygop Team•Last updated: Feb 2026
The 8 Primitive Types
- byte — 1 byte, range: -128 to 127 (saves memory in large arrays)
- short — 2 bytes, range: -32,768 to 32,767 (rarely used)
- int — 4 bytes, range: ~±2 billion (most common for whole numbers)
- long — 8 bytes, range: ~±9 quintillion (use 'L' suffix: 100L)
- float — 4 bytes, ~7 decimal digits (use 'f' suffix: 3.14f)
- double — 8 bytes, ~15 decimal digits (default for decimals)
- boolean — true or false only (for conditions and flags)
- char — 2 bytes, single Unicode character (use single quotes: 'A')
Primitive Types in Action
Example
public class DataTypes {
public static void main(String[] args) {
// Integer types
byte smallNumber = 100; // -128 to 127
short mediumNumber = 30000; // -32,768 to 32,767
int regularNumber = 2000000000; // ~±2 billion
long bigNumber = 9000000000L; // Note the 'L' suffix!
// Floating-point types
float price = 19.99f; // Note the 'f' suffix!
double precise = 3.141592653589;
// Boolean type
boolean isJavaFun = true;
boolean isFriday = false;
// Character type
char letter = 'J';
char symbol = '@';
char unicode = '\u0041'; // Unicode for 'A'
System.out.println("byte: " + smallNumber);
System.out.println("short: " + mediumNumber);
System.out.println("int: " + regularNumber);
System.out.println("long: " + bigNumber);
System.out.println("float: " + price);
System.out.println("double: " + precise);
System.out.println("boolean: " + isJavaFun);
System.out.println("char: " + letter);
System.out.println("unicode: " + unicode);
}
}Try It Yourself: Explore Data Types
Try It Yourself: Explore Data TypesJava
Java Editor
✓ ValidTab = 2 spaces
Java|21 lines|791 chars|✓ Valid syntax
UTF-8