Today I learned the Java operator, and here's what we're going to focus on today:
The operator "+" is supplemented in 1.java to connect two strings, for example: "ABC" +123 results in "abc123", two integer parts of the result of a division of integers, for example: 3/2 is not 1.5 but 1; Java in the remainder budget (% Can also be left over for integers, such as: 16.3%5=1.3; You can perform arithmetic operations on char data, but not on a Boolean (because the char type can be automatically converted to integral and floating-point types, and Boolean cannot convert to any type) For example: ' A '%4=1 ; The operands of the + + (-) operator must be a variable, not a constant and an expression (from an assignment point of view, ++a and a++ are the same, both add a value of a; But from the point of view of the operation of the expression, the result is different, ++a is the first one, and then the value of the additional one, a++ the opposite.
2. When using the println output, the contents of the parentheses are represented by an expression, plus the contents of the output quotation marks! For example: System.out.println (3>4) output False (the relational operator gets the result of a Boolean type, Value is ture or false, such as:< <=!= comparison is ture; > >= = = is false), System.out.println ("3>4") output 3>4. Be sure to write.
3. The difference between a logical operator and a bitwise operator: The Boolean data is logically "with, or, not, XOR, or", and the result is still Boolean, with a logical operator; an integral type (including Byte, short, int, Long) and bits of character type (char) data is the bitwise operator when the result is an integer.
4. Logical operators: XOR or (^) with false;& (&&) Two true is true, the rest are false; A true one is true, all leave is false;
5. Logic &, | and short circuit &&, | | The difference between: (in any case two times) using &, | When doing logical operations, the expressions on both sides of the operator are executed, and the result of the last two expressions is performed with or operations; (sometimes only the left-hand side of the operation can be obtained) using &&, | | When doing a logical operation, the expression on the right will not be executed if the result of the left expression of the operator is evaluated only to determine the result of the OR.
6. Bitwise operator: The left highest bit is the sign bit, 0 is positive, 1 is negative, and the negative number takes the form of complement. The binary of negative numbers means that the absolute value is reversed, plus one.
7. Two values for participating in the budget,& operation if two corresponding bits are 1, then the change result is 1, otherwise 0, that is, 0&0=0,0&1=0,1&0=0,1&1=1;| operation, as long as two corresponding digits have one 1, the change result is 1, that is 0 |0=0,1|0=1,0|1=1,1|1=1;^ operation, as long as two corresponding bit the same, then 0, otherwise 1, that is 0^0=0,1^0=1,0^1=1,1^1=0; example: 00101010^00010111 result is: 00111101.
8. "<<" Left (arrow left) operation, A<<b will be the binary form of integer a bit left B, right (low) free out of the B-position complement 0, the original left of B-bit was discarded; >> "Right" (arrow to the right) operation, right Shift B, left (high) free out of the B position to complement the original symbol bit, the original rightmost b is discarded; ">>>" and ">>" is different from ">>>" Left (high) free out of b bit 0, and ">>" complement the original symbol bit
9. Shift rule: Move one, a*2 two, a*2*2 three, a*2*2*2 .... And so on, that is to move several times on the 2 square.
The true number of shifts in the shift operation is not necessarily the specified B bit, when A is an int (or byte, short, char), the system first takes B to 32 modulo, the result is the true number of shift digits, and when a is long, the system first takes B to 64 modulo, For a 32-bit int, the shift over 32 is meaningless, and the long data is similar, so 10>>32 is equivalent to 10>>0, and actually to the right 0-bit, that is, there is no reverse migration.
10. Take a bit, take a few to use a few one;
11. When the type is inconsistent on either side of the assignment operator, if the left variable has a large range of data types, the data type on the right is automatically converted to the same data type on the left, and then to the left variable, otherwise the type conversion operator needs to be coerced. For example: short i; I=i+2 (because 2 is integral type, so the first addition of I is converted to the int type, that is, the right is int type and I is short, solid error, two operations, not converted i+=2 (because + = is the extended assignment operator, solid for an operation, internal automatic conversion).
12. Extension operators (+ + =, etc.) For example: A+=b,a must be a variable, B can be a variable, a constant, an expression, and so on.
13. The conditional operator (. : Is the only one by one three-mesh operator in Java. < expression 1>?< expression 2>:< expression 3> (the expression is 1 must be Boolean).
14. Automatic conversion rules: levels from low to High: Byte->short->int->long->float->double;char+char->int,boolean cannot be converted to any type.
15. Cast Format: (Target data type) variable or expression, when cast because the range of the destination data type is less than the range of the type to be converted, truncation occurs during conversion, resulting in high data loss or precision degradation. (High truncation, left low)
16. Byte, short, char automatically converted to integer after operation, an integer default is int type, byte, short, char can be directly assigned to integer constants, as long as it does not exceed its range.
17. Called classes and methods as long as they are not under the Java.lang package, it is necessary to drop the package at the beginning of the code. Call the static method, do not need the new object, can be called directly, otherwise the new object is available, such as: Object name Class name =new object name ().
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service