Java Data types

Java Data types

Every variable in java must be supposed as the specified datatype.

And these data types are classified into two types.

  • Primitive Datatypes

  • Non-Primitive Datatypes.

Primitive DataTypes:

Primitive DataTypes tells us the size and type of variable values.

Primitive datatypes mainly include datatypes such as :

  • byte

  • short

  • int

  • long

  • float

  • double

  • boolean

  • char

1 Byte is equal to 8 bits

DataTypeSizeRanges From
byte1 byteranges from -128 to 127.
short2 bytesranges from -32,768 to 32,767.
int4 bytesranges from 2,147,483,648 to 2,147,483,647.
long8 bytesranges from -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
float4 bytesstores the fractional numbers.
double8 bytesstores the fractional numbers.
boolean1 bitstores true or false values.
char2 bytesstores a single character/ ASCII values.

Non-Primitive DataTypes:

  • Strings

  • Arrays

  • Classes

Example:

int number = 5;              // Integer (whole number)
float floatNumber = 5.99f;   // Floating point number
char letter = 'D';           // Character
boolean choice = true;       // Boolean
String text = "Hello";       // String

Did you find this article valuable?

Support Smart Cookie ๐Ÿช by becoming a sponsor. Any amount is appreciated!

ย