Data Types in Java

Java programming language is a strictly typed and the variable should be declared with an appropriate data type before the usage. Java provides Primitive data types like byte, short, int, long, float, double, boolean, char.

String is a special data type to hold a sequence of char and the value should be enclosed within double quotes (i.e. "Hello World") instead of single quotes. Java also provides the non-primitive data types like class, interface, array, etc.

Primitive Data Types

Data Type Size Default Value (for fields / instance variable)
byte 1 byte false
short 2 byte 0
int 4 byte 0
long 8 byte 0L
float 4 byte 0.0f
double 8 byte 0.0d
boolean 1 bit false
char 2 byte '\u0000'

Non-Primitive Data Types

Note: The following list contains the commonly used predefined data types. The data types like class, interface, enum, etc., can be explained in details in the later session.

Data Type Size Default Value (for fields / instance variaable)
String ~ null
array ~ null