What are the data types in Java?

0

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

  1. Primitive data types
  2. Non-primitive data types

1) Primitive data types : There are eight primitive data types in Java

Data TypeSizeRangeDefault Values
boolean1 bittrue or flaseflase
char2 bytesone character/letter or 0 to 65,536 (unsigned) , ASCII values\u0000
byte1 byte128 to 1270
short2 bytes32,768 to 32,7670
int4 bytes2,147,483,648 to 2,147,483,6470
long8 bytes9,223,372,036,854,775,808 to 9,223,372,036,854,775,8070
float4 bytes6 to 7 significant decimal digits0.0
double8 bytes15 significant decimal digits0.0

2) Non-Primitive Data Types : Non-primitive data types are created by the programmer, and are not defined by Java language.

Examples : Strings, Arrays, Classes, Interface etc.
String myStrVar = “Hello, It’s String Variable”;

Difference between primitive data types and non primitive data types

Primitive Data TypeNon-primitive Data type
This are predefined in JavaThis are created by the programmer and is not defined by Java
A primitive type always has a valueNon-primitive types can be null.
Primitive type starts with a lowercase letter.Non-primitive types start with an uppercase letter.

Leave a Reply

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