Data Types in Java

Data Types in Java

Data types specify the different sizes and values that can be stored in a variable. There are 2 types of data types in Java:

1. Primitive data types – byte, short, int, long, float, double, boolean, char.
2. Non-primitive data types – String, Arrays, Classes, Interface.

data types in java

1. Primitive data types-

A primitive data types are predefined by the programming language. The size of a primitive type depends on the data type. They do not have additional methods. Their value can never be null and are always written in lowercase.

Data TypeSizeDescription
byte1 byteStore from -128 to 127
short2 bytesStores from -32768 to 32767
int4 bytesStores from -2147483648 to 2147483647
long8 bytesStores from -9223372036854775808 to 9223372036854775807
float4 bytesStores fractional numbers having 6 to 7 decimal digits
double8 bytesStores fractional numbers having 15 decimal digits
boolean1 bitStores true or false
char2 bytesStores a single character/letter/ASCII values

2. Non-Primitive data types-

Non-primitive data types are not predefined in java like primitive data types. They are created by the programmer according to their need and can be null. They are used to store a group of values. The variable of a non-primitive data type is called an object reference variable. Non Primitive types are used to call methods to perform certain operations.


So these were the data types in java. We hope the concept was clear to you. For daily updates and more such content do follow us on Instagram.

Keep programming!



Leave a Reply

Your email address will not be published. Required fields are marked *