Core Java Tutorial


Data Types in Java

Data types are used to identify what kind of values are stored in a variable. Data types are defined before the variable name.There are mainly two different data types are there.

       1.Primitive Data Types
       2.Non-Primitive Data types
Data type and Variables

Here int is data type of integer value 50 for the variable value.

Primitive data types

Primitive data types are predefined data types in java.There are mainly eigth primitive data types are there.see the below table of comparison between those eight data types

Primitive Data Types
S.No Name Explanation Example Size
1 int Integer Values int a=10; 4Bytes(32Bit)
2 short Integer Values short a=10; 2Bytes(16Bit)
3 long Integer Values long a=10; 8Bytes(64Bit)
4 byte Integer Values byte a=10; 1Bytes(8Bit)
5 float Decimal Values float a=10.2f; 4Bytes(32Bit)
6 double Decimal Values double a=10.0; 8Bytes(64Bit)
7 char charaecter Values char a='K'; 2Bytes(16Bit)
8 boolean true or false Values boolean a=true; 1 Bit

Non-Primitive Data Types

Examples for non-primitive data types are Strings,Arrays etc.. you will learn each one separately in next couple of minutes.