Integer

byte:

  • The byte data type is an 8-bit signed two’s complement integer.
  • The minimum value is -128 (-2^7)
  • The maximum value is 127 (inclusive)(2^7 -1)
  • The default value is 0
  • The byte data type is used to save space in large arrays, mainly in place of integers, since a byte is only a quarter of the size of an int.
  • Example: byte a = 100 , byte b = -50

short:

  • The short data type is a 16-bit signed two’s complement integer.
  • The minimum value is -32,768 (-2^15)
  • The maximum value is 32,767 (inclusive) (2^15 -1)
  • The short data type can also be used to save memory. A short is only half the size of an int
  • The default value is 0.
  • Example: short s = 10000, short r = -20000

int:

  • The int data type is a 32-bit signed two’s complement integer.
  • The minimum value is – 2,147,483,648.(-2^31)
  • The maximum value is 2,147,483,647(inclusive).(2^31 -1)
  • Int is generally used as the default data type for integral values unless there is a concern about memory.
  • The default value is 0.
  • Example: int a = 100000, int b = -200000

long:

  • The long data type is a 64-bit signed two’s complement integer.
  • The minimum value is -9,223,372,036,854,775,808.(-2^63)
  • ┬áThe maximum value is 9,223,372,036,854,775,807 (inclusive). (2^63 -1)
  • The long type is used when a wider range than int is needed.
  • Default value is 0L.
  • Example: long a = 100000L, int b = -200000L

Next: Float