Data Types
In Java, data types specify the size and type of values that can be stored in variables. Java has two categories of data types: Primitive data types and Reference data types.
Primitive Data Type
Primitive data types are predefined by the language and are named by a reserved keyword. They represent single values and are not objects.
Different Types
byte
8-bit signed integer
1 byte
0
short
16-bit signed integer
2 bytes
0
int
32-bit signed integer
4 bytes
0
long
64-bit signed integer
8 bytes
0L
float
32-bit floating point
4 bytes
0.0f
double
64-bit floating point
8 bytes
0.0d
char
16-bit Unicode character
2 bytes
'\u0000'
boolean
true or false
not precisely defined
false
Limits or Range
byte
8
-128
127
short
16
-32,768
32,767
int
32
-2,147,483,648
2,147,483,647
long
64
-9,223,372,036,854,775,808
9,223,372,036,854,775,807
float
32
Approximately ±3.40282347E+38F
Approximately ±1.40239846E-45F
double
64
Approximately ±1.7976931348623157E+308
Approximately ±4.94065645841246544E-324
char
16
0
65,535
boolean
not precisely defined
true or false
true or false
Reference Data Types:
Reference data types are objects that hold references to the memory location where the data is stored. They include classes, interfaces, arrays, and enumerations.
Primitive Wrapper Classes:
These are reference data types that wrap primitive data types into objects. For example:
Byte
Short
Integer
Long
Float
Double
Character
Boolean
These wrapper classes are useful when working with collections or when you need to treat primitive types as objects.
Last updated
Was this helpful?