Primitive data types : Java

The eight primitive data types in Java are:
  • boolean, the type whose values are either true or false
  • char, the character type whose values are 16-bit Unicode characters
  • the arithmetic types:
    • the integral types:
      • byte
      • short
      • int
      • long
    • the floating-point types:
      • float
      • double
Values of class type are references. Strings are references to an instance of class String.

Boolean
Values of type boolean are not converted implicitly or explicitly (with casts) to any other type. But the programmer can easily write conversion code:
final int i = b?1:0;
final double d = b?1.0:0.0;
final boolean b = i>0?true:false;


Primitive data types in Java
TypeDescriptionDefaultSizeExample Literals
booleantrue or falsefalse1 bittruefalse
bytetwos complement integer08 bits(none)
charUnicode character\u000016 bits'a''\u0041''\101''\\''\'''\n''ß'
shorttwos complement integer016 bits(none)
inttwos complement integer032 bits-2-1012
longtwos complement integer064 bits-2L-1L0L1L2L
floatIEEE 754 floating point0.032 bits1.23e100f-1.23e-100f.3f3.14F
doubleIEEE 754 floating point0.064 bits1.23456e300d-1.23456e-300d1e1d


Comments

Popular Posts