What are the primitive Integer and Floating-Point Data Types in java

Integer Data Types:
These data types represents integer numbers, i.e. numbers without any fractional parts or decimal points (For example, 113, -245, 0, 1056,…) Comes under this category. Integer data types are again sub divided into byte, short, int, and long types.
Data type | Memory size | Min and Max values |
byte | 1 byte(8bits) | -128 to +127 |
short | 2 bytes | -32768 to + 32767 |
int | 4 bytes | -2147483648 to +2147483647 |
long | 8 bytes | -9223372036854775808 to +9223372036854775807 |
Memory representation of maximum and minimum values of a byte :
![]() |
In the same way we can calculate the remaining integer data types .
Syntax:
byte <variable_Name> = <integer number with in the range of a byte>;
short<variable_Name> = <short number with in the range of a short>; long <variable_Name> = <integer number with in the range of a long>l; |
Example :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
class MinAndMax { byte byteMaxValRange = 127; // byte byteMaxValRange = 128 ; The compiler will give an error byte byteMinValRange = -128; // byte byteMinValRange = -129 ; The compiler will give an error short shortMaxValRange = 32767; short shortMinvalRange = -32768; int intMaxValRange = 2147483647; int intMinvalRange = -2147483648; long longMaxValRange = 9223372036854775807L; long longMinvalRange = -9223372036854775808L; } |
Floating-Point Data Types:
Floating-Point Data Types are useful to represent numbers with decimal point (Example : 3.16, 0.145, -1.278 ,…) . These are again classified as float (single precision floating point number) and double (double precision floating point number). The difference exists essentially in the number of digits, they can represent accurately after the decimal point. this accuracy is also called precision.
Data type | Memory Size | Min and Max Values |
float |
4 bytes |
-3.4e38 to -1.4e-45 for -ve values 1.4e-45 to 3.4e38 for +ve values
|
double |
8 bytes |
-1.8e308 to -4.9e-324 for -ve values |
note : Difference between the float and double is, float can represent up to 7 digits accurately after decimal point, whereas double can represent up to 15 digits accurately after a decimal point.
Syntax:
float <variable_Name> = <decimal number with in the range of a float>F;double<variable_Name> = <decimal number with in the range of a double>d; |
Example Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
class dataTypesExe { public static void main(String[] args) { byte rollNum = 10; int totalMarks = 500; float percentage = totalMarks/6F; System.out.println("Roll number : "+rollNum); System.out.println("Total marks : "+totalMarks); System.out.println("Percentage : "+percentage); } } |
Execution Result :
1 2 3 |
Roll number : 10 Total marks : 500 Percentage : 83.333336 |
Literal is of type long, if it ends with the letter L or l otherwise it is of type int.
A floating-point literal is of type float , if it ends with the letter F or f otherwise its type is double and it can optionally end with the letter D or d.

Related Posts : |
![]() |
What are the primitive data types in java |