java2db

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



Integer and Floating-Point Data Types in javaInteger 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 :

Integer and Floating-Point Data Types in java

create a servlet If the sign bit indicates 0  ,  it is a positive number otherwise (if 1) , it is a negative number.

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>;
int    <variable_Name> = <integer number with in the range of an int>;

long <variable_Name> = <integer number with in the range of a long>l;

 

 Example :

 

 

Integer and Floating-Point Data Types in javaFloating-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
4.9e-324 to 1.8e307 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:

Execution Result :

Integer and Floating-Point Data Types in java Literal is of type long, if it ends with the letter L or l otherwise it is of type int.

Data Types in java 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
   [will not be published]



^ <