Primitive Data Types

There are eight primitive information types, which are supported by Java. Primitive data types are predefined by the dialect and named by a catchphrase. This section discusses these data types in detail.

byte:

• byte information sort is a 8-bit marked two’s supplement whole number
• Maximum worth is 2^7 -1, which is equal to 127. This value is also included in the range of these values.
• Minimum worth is -2^7, which is equal to -128.
• Default value stored in a variable of this type is 0.
• byte information sort is utilized to spare space in vast exhibits, principally set up of numbers, since a byte is four times littler than an int.
• Example:
byte x = 200, byte y = -20

short:

• short information sort is a 16-bit marked two’s supplement number.
• Maximum value is 2^15 -1, which is equal to 32,767. This number is also included in the range.
• Minimum value is -2^15, which is equal to -32,768.
• short information sort can likewise be utilized to spare memory as byte information sort. A short is 2 times littler than an int
• The default value for this data type is 0.
• Example:
short x = 425164, short y = -76686

int:

• int information sort is a 32-bit marked two’s supplement number.
• Maximum value for this data type is 2^31 -1, which is equal to 2,147,483,647. This number is also included in the range for this data type.
• Minimum value for this data type is -2^31, which is equal to – 2,147,483,648.
• int is for the most part utilized as the default information sort for its indispensable qualities unless there is a worry about memory.
• The default value for this data type is 0.
• Example:
int x = 826378, int y = -64782

long:

• long information sort is a 64-bit marked two’s supplement whole number.
• Maximum value for this data type is 2^63 -1, which is equal to 9,223,372,036,854,775,807.
• Minimum value for this data type is -2^63, which is equal to -9,223,372,036,854,775,808.
• This sort is utilized when a more extensive memory range than int is required.
• The default value for those data type is 0l.
• Example:
long x = 174636l, int y = -536452l

float:

• float is a data type, which is know for its solitary exactness, 32-bit IEEE 754 gliding point.
• float is for the most part used to spare memory in vast exhibits of coasting point numbers.
• The default value for this data type is 0.0f.
• float information sort is never utilized for exact values, for example, money.
• Example:
float x = 254.3f

double:

• double information sort is a float with twofold exactness 64-bit IEEE 754 drifting point.
• This information sort is for the most part utilized as the default information sort for decimal qualities.
• double information sort ought to never be utilized for exact values, for example, money.
• The default value for this data type is 0.0d.
• Example:
double x = 321.4

boolean:

• boolean information sort speaks to one bit of data.
• Any boolean variable can assume one of the two values: true or false.
• This information sort is utilized for basic banners that track genuine/false conditions.
• The default value for this data type is false.
• Example:
boolean check = true;

char:

• char information sort is a solitary 16-bit Unicode character.
• Maximum value for a variable of this type is “\uffff” (or 65,535 comprehensive).
• Minimum value for a variable of this type is “\u0000” (or 0).
• char information sort is utilized to store any character.
• example:
char text =‘a’