Tuesday, August 29, 2006

Java Primitive Types

  • boolean - 1 bit - [true, false]
  • char - 16 bits - [\u0000, \uffff] inclusive
  • byte - 8 bits - [-128, 127] inclusive
  • short - 16 bits - [-32768, 32767] inclusive
  • int - 32 bits - [-2^31, 2^31 - 1] inclusive
  • long - 64 bits - [-2^63, 2^63 - 1] inclusive
  • float - 32 bits
  • double - 64 bits
Note:
  • boolean is the only boolean type, others are all numeric types.
  • char is one of the integral types. A char literal should be enclosed in a pair of single quotes.
  • float and double are the floating-point types. NaN stands for Not a Number, NEGATIVE_INFINITY and POSITIVE_INFINITY for mathematical infinity.
  • default values for boolean is false, for char, \u0000, for integers, 0, for floating-points, 0.0.
  • float aFloat = 802.649F is correct, float aFloat = 802.649 is wrong.

No comments: