Short S1 = 1; S1 = S1 + 1
for short S1 = 1; S1 = s1 + 1; Because the type of the expression is automatically promoted by the s1+1 operation, the result is of type int, and when assigned to the short type S1, the compiler reports an error that requires a cast type.
for short S1 = 1; S1 + = 1; since + = is a Java-language-defined operator, the Java compiler will treat it specially, so it compiles correctly.
Byte
Byte has a value range of -128~127 and occupies 1 bytes (-2 of 7 to 2 of 7) (1)
Char
Int
The value range of int is ( -2147483648~2147483647), which takes 4 bytes (-2 of 31 to 2 31-1)
Short
Short has a value range of -32768~32767, which takes 2 bytes (-2 of 15 to 2 15-1)
Long
The Long value range is ( -9223372036854774808~9223372036854774807), which takes up 8 bytes (-2 of the 63-to-2 63-square-1)
Boolean
The data type used to hold characters, 2 bytes, Unicode encoded, and ASCII compatible with the first 128 bytes of encoding
Character storage range in \u0000~\uffff, when defining the character type of data should pay attention to ", such as ' 1 ' means the character ' 1 ' instead of the value 1,
char c = ' 1 ';
We try to output C and see, System.out.println (c); The result is 1, and if we output it like this System.out.println (c+0);
float and double are data types that represent floating-point type, the difference between them is that their accuracy is different
Float 3.402823e+38 ~ 1.401298e-45 (e+38 is multiplied by 10 for 38 times, similarly, e-45 means 10 minus 45 times) consuming 4 bytes
Double 1.797693e+308~ 4.9000000e-324 takes 8 bytes
Double type more than float type storage range, more accurate, so the usual floating-point data is not declared in the case of double type, if you want to indicate that a data is float type, you can add "F" after the data.
The floating-point data is not completely accurate, so sometimes it is normal to have floating in the last few decimal places when calculating.
Basic data Type Range