Primitive Data Types
Lesson 1 of 16 in Coddy's Strings and Arrays in Java course.
Before we dive into the course, let's clarify data types in Java.
Data types are divided into two groups:
- Primitive data types
- Non-primitive data types
Primitive data type specifies the size and type of variable values, and it has no additional methods.
The primitive data types in Java are byte, short, int, long, float, double, boolean and char.
| Data Type | Size | Description |
|---|---|---|
byte | 1 byte | Whole numbers from -128 to 127 |
short | 2 bytes | Whole numbers from -32,768 to 32,767 |
int | 4 bytes | Whole numbers from -2,147,483,648 to 2,147,483,647 |
long | 8 bytes | Whole numbers from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
float | 4 bytes | Fractional numbers up to 6 to 7 decimal digits |
double | 8 bytes | Fractional numbers up to 15 decimal digits |
boolean | 1 bit | true or false values |
char | 2 bytes | Single character/letter |
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
Try it yourself
This lesson doesn't include a code challenge.