Introduction
Data types are one of the fundamental concepts in Java programming.
Whenever we write a program, we need to store different kinds of information, such as numbers, names, decimal values, and true or false conditions.
Java provides different data types to store these values.
A data type specifies what kind of value a variable can store.
For example:
Age β Integer
Name β Text
Salary β Decimal number
Grade β Character
Passed β True or False
Let's understand data types in Java in detail.
1. Types of Data Types in Java
Java data types are divided into two major categories:
Primitive Data Types
Non-Primitive (Reference) Data Types
2. Primitive Data Types
Primitive data types are the basic built-in data types provided by Java.
Java has 8 primitive data types:
byte
short
int
long
float
double
char
boolean
Let's understand each data type.
1. byte
The byte data type is used to store small whole numbers.
Memory: 1 byte
Range: -128 to 127
Example:
byte age = 21 ; System .β¦