Variables, type conversions, operators

Variables: divided into member variables and local variables

1. Local variables are stored in the stack frame, member variables are in the heap, and static member variables are in the static area (all areas of memory)

2. Local variables must have values ​​before they are used; member variables can only be declared, and the system can give default values ​​based on the type, either only declaration or assignment at the same time as the declaration, because assignment cannot be placed under the class alone! If you must assign a value, add {} on both sides of the assignment

3. For member variables, those with static modification are called static member variables, and those without being instance variables. Static methods can only use static member variables, and general methods can be used.

4. The principle of proximity: When a member variable and a local variable have the same name, use the nearest one

================================================

Type conversion

1, byte short (char) int long float double
----------------The higher the precision -------------->

2. Small conversion is called implicit conversion, big conversion is called forced conversion (loss of precision, risk of overflow)

3. When the precision of all variable types in the expression is lower than int, the type of the result is int
Insert picture description here
Insert picture description here
4. When the precision of a type variable in the expression is higher than int, the type of the result is the type with the highest precision in the expression
Insert picture description here
5 , Char

Instead of output AB
6. When there is String in the expression, the + in front of String means addition, and the latter means splicing.
If you want to use addition later, use parentheses
7.
The result of two special divisions 0.0/0.0 is NaN (not a number) and
the result of 1.0/0.0 is Infinity, which means gigantic

================================================
operator
1. Arithmetic operator (+-* /% ++ --)
2. Assignment operator (= += -= *= /= %=)
3. Comparison operator (== !=> <>= <= )
4. Bitwise operators (& | ^ ~ << >>> >>)
5. Logical operators (& | && || ^ !)
6. Ternary operators (x?y:z)

Then I have always wanted to memorize their priority, but I have seen many categories and priorities on the Internet, but they are not the same. I currently remember the priority (if wrong, please correct me)

Arithmetic operator-comparison operator-bit operator-logical operator-ternary operator-assignment operator
----------------------- ------------------High to low----------------------------- ------------->

Small details to the
1, instanceof: Comparison of reference only type, or the value of the variable is determined to a reference data type is not
Insert picture description here
2, the four logical operators
&& and || short-circuit function, and so the efficiency ratio & | high
that shorting If the previous conditions are met, the latter need not be executed (& and | will still be executed)
eg:
Insert picture description here

Guess you like

Origin blog.csdn.net/ExceptionCoder/article/details/107042311