Java Basics Summary (third, operator)

Source: Internet
Author: User
Tags arithmetic operators bitwise bitwise operators

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)

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.