变量定义
其中byte、short、int、long都是表示整数的,只不过他们的取值范围不一样 :
byte 的取值范围为 -128~127,占用1个字节(-2的7次方到2的7次方-1)
short 的取值范围为 -32768~32767,占用2个字节(-2的15次方到2的15次方-1)
int 的取值范围为 (-2147483648~2147483647),占用4个字节(-2的31次方到2的31次方-1)
long 的取值范围为 (-9223372036854774808~9223372036854774807),占用8个字节(-2的63次方到2的63次方-1)
类型转换
Java 可以将低精度的数字赋值给高精度的数字型变量,反之则需要强制类型转换。
溢出
隐式转换 char byte short
运算
任何数据库类型 + String = String
符合赋值运算符自动转换
short + int
int + int
(short) int
short num += 30;