- Byte : 8-bit signed two’s complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive)
- Short : 16-bit signed two’s complement integer. It has a minimum value of -32,768 and a maximum value of 32,767 (inclusive).
- Int : 32-bit signed two’s complement integer. It has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 (inclusive)
- Long : 64-bit signed two’s complement integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive)
- Float
- If you want to create a float, you should end your number with
f
(i.e.:3.6f
). float b= 3.6;
will give you this error.Error:Unresolved compilation problem: Type mismatch: cannot convert from double to float
float b= 3.6; without the f will mean java thinks its
a double and it will fail
so 3.6 is seen as a decimal and does not convert to float!
- Double
double b= 3.6; will give you a Double no problem
more info about java double and float
double
is a 64-bit precision IEEE 754 floating point, while float
is a 32-bit precision IEEE 754 floating point. As a float
is less precise than a double
, the conversion cannot be performed implicitly.Unboxing: The automatic transformation of wrapper types into their primitive equivalent is known as Unboxing.
No comments:
Post a Comment