Basic data types in JAVA

  • 2020-06-01 09:54:07
  • OfStack

byte: the smallest data type in java. 1 byte /8 bits. -128 (2^7) ~127 (2^7-1), the default value is 0.

short: short integer, 2 bytes /16 bits, range from -32768 (--2^15) to 32767 (2^15-1), default value 0

int: integer, 4 bytes /32 bits, range from -2147483648 (-2^31) to 2147483647 (2^31-1), default value 0

long: long integer, 8 bytes /64 bits, -2^63 (-2^63) ~2^63-1 (2^63-1), default value 0L

float: floating point, 4 bytes /32 bits, used to store Numbers with decimal points (the difference with double is that the float type has only 6 to 7 valid decimal points), with a default value of 0

double: double-precision floating point, 8 bytes /64 bits, default value 0

char: character type, single character, 2 bytes /16 bits, 0 ('\u0000') ~65535 ('\uffff'), default value is empty

boolean: Boolean, 1 byte, true or false (only two values, true, false), default value false

Small capacity -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- - > Large capacity

byte,short,char < < int < < long < < float < < double

byte < < short

byte and char, short and char do not have implicit conversions and can only cast each other.


Related articles: