Third, Operators operators
Assignment Operators (Assignment operator)
= + = =%= *=/= <<= >>= >>>= &= ^= |=
public class Bytedemo {public static void Main (string[] args) { byte b1=2; byte b2=3; B1= (Byte) (B1+B2); addition, turn int b1+=b2; Assignment, do not go int }}
B1+=B2; and b1=b1+b2; Is it exactly equivalent?
The answer is in the negative. The byte type parameter and operation are converted to type int first, so coercion type conversion is required. (Can put "B11+=B2;" As to "b1= (byte) (B1+B2);" The optimization! )
Comparison Operators (comparison operator)
> >= < <= instanceof
Equality Operators (same operator)
= = =
Arithmetic Operators (arithmetic operator)
+ - * / %
Shift Operators (shift operator)
>> << >>>
public class Test {public static void main (string[] args) {String S1 = integer.tobinarystring (-1); System.out.println (S1); 11111111,11111111,11111111,11111111int I1 = integer.valueof ("1111111100000000", 2); System.out.println (I1); 65280int i2 = i1 >> 1; System.out.println (integer.tobinarystring (I2)); 01111111,10000000int i3 = I1 << 1; System.out.println (integer.tobinarystring (i3)); 00000001,11111110,00000000int i4 = i1 >>> 1; System.out.println (Integer.tobinarystring (I4)); 01111111,10000000//0-bit extension and sign bit extension System.out.println (integer.tobinarystring ( -1 >> 1)); 11111111,11111111,11111111,11111111// -1system.out.println (integer.tobinarystring ( -1 >>> 1)); 01111111,11111111,11111111,11111111//2147483647}}
Bitwise Operators (bitwise operator)
& | ^ (Bitwise XOR) ~ (bitwise reversed)
Logic Operators (logical operator)
&& & | | | !
Conditional Operators (conditional operator)
?:
public class Test {public static void main (string[] args) {Boolean b = true;int i = b? 1:2; System.out.println (i);//1}}
Other operators
+ +--
public class Testaction {public static void main (string[] args) {int i = 2; System.out.println (i++);//2system.out.println (i);//3int a = i++ + i;//3+4=7system.out.println (a); int b = i++ + ++i;//3 +5=10i++; System.out.println (b); System.out.println (i);//7for (int j = 0; J <; J + +) {i = i++;} System.out.println (i);//7}}
Java Basics Summary (third, operator)