What is a Data Type?
A data type tells Java what kind of data a variable can store.
For example:
- Numbers
- Characters
- True or false values
In Java, data types are mainly divided into two types:
1. Primitive Data Types
Primitive data types are the basic building blocks in Java.
Java has 8 primitive data types.
Integer types
These are used to store whole numbers:
intbyteshortlong
Example:
int age = 25;
Boolean type
Used to store true or false values:
boolean
Example:
boolean isJavaEasy = true;
Decimal (Floating-point) types
Used to store numbers with decimal points:
floatdouble
Example:
double price = 260.30;
Character type
Used to store a single character:
char
Example:
char grade = 'A';
2. Non-Primitive Data Type
Non-primitive data types are more complex and can store multiple values.
String
The main non-primitive data type is:
String
A String is used to store text or words.
Example:
String name = "Karthick";
Top comments (0)