1. When the value of the assignment exceeds the scope of the declared variable, an error is given!
BYTE A = 200//Will error due to out of range.
byte a = (byte) 200;//does a cast, it will not error, but will be out of range, the excess will be added from the beginning,
Because the range of byte is -128~127, it is the result of -128+73.
2. When declaring an integer type, the default is int type (4 8-bit), and no error if the specific value is smaller than the range of the declared variable.
Example: short a = 222;
3.long L = 88888888888l Obviously, this long string of numbers is better than int's range of values, so it will be an error, but because it does not exceed the range of long values,
So we can declare a long variable to fit it, but we need to add "L" to the back (case insensitive).
4. Declare a float variable, such as float F = 12.555, because the default type of declaring a decimal is a double type (8 eight-bit), so when converting from high precision to low-precision float (4 8-bit), the accuracy error is lost, and "F" is added to the rear Convert it to a float type, you will not get an error.
5.char is used to declare a character, char C = ' E '; System.out.println (c); the output is this character, but when the operation is performed
Use the ASCLL encoded position of the variable.
char c2 = ' \ n '; indicates a newline; The operation is also its position!
6. Type conversion priority: Double float long int char short byte
7.short s = 133;
char c = ' a ';
Short S1 = s+c; The output will be error, because the two number is added, the default is int type, with short to install it, will report loss accuracy errors,
You need to add a cast at this point: short S1 = (short) (S+C);
8. Implicit conversion: from low-precision automatic conversion to high-precision; for example: long L = 5834; The default numeric type is int type, but since you
With long to declare, your accuracy than I am still higher, then I will not say anything, silently turn over it.
9. Display conversion: Also known as cast, generally by high precision steering low precision. For example short S1 = (short) (s+c); I was more precise than you.
int, but you use a low-precision short to install me, I certainly do not agree (error), said, to be forced to convert, do not agree to agree.
10.+= 's Assignment principle: byte b = 4;char c = 0.4;b + = C; Because the char priority is higher than Byte, B = B+c,
is to give an error, but B + = c, but not error, because it first assigns the value of C to B, after assignment, B becomes Char
Type, and then the value of B, Char has a higher priority, so there is no error.
Understanding of variable Assignment in Java