Saturday, June 14, 2014

What are the Data Types supported by Java?

The eight Primitive Data types supported by Java are:
  • 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 floatis a 32-bit precision IEEE 754 floating point. As a floatis less precise than a double, the conversion cannot be performed implicitly.


Autoboxing: The Java compiler brings about an automatic transformation of primitive type (int, float, double etc.) into their object equivalents or wrapper type (Integer, Float, Double,etc) for the ease of compilation.

Unboxing: The automatic transformation of wrapper types into their primitive equivalent is known as Unboxing.

No comments:

Post a Comment