Java operator Precedence

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

Java operator Precedence

Serial number

Symbol

Name

Adhesion (with operands)

Mesh number

Description

1

.

Point

From left to right

Binocular

( )

Parentheses

From left to right

[ ]

Square brackets

From left to right

2

+

Positive sign

From right to left

Monocular

-

Minus sign

From right to left

Monocular

++

Self-increment

From right to left

Monocular

Prefix increment, suffix increment

- -

Self-reduction

From right to left

prefix minus, suffix minus

~

Bitwise non-/FETCH-complement operation

From right to left

Monocular

Logical Non-

From right to left

Monocular

“!” cannot be associated with "="

3

*

By

From left to right

Binocular

/

Except

From left to right

Binocular

Integer division: The integer part of the fetch, the fractional part removed, not rounded

%

Take surplus

From left to right

Binocular

4

+

Add

From left to right

Binocular

-

Reducing

From left to right

Binocular

5

<<

Left shift operator

From left to right

Binocular

>>

Signed right shift operator

From left to right

Binocular

>>>

Unsigned Right Shift

From left to right

Binocular

6

<

Less than

From left to right

Binocular

Relational operator "greater than" description

<=

Less than or equal to

From left to right

Binocular

>

Greater than

From left to right

Binocular

>=

Greater than or equal to

From left to right

Binocular

instanceof

Determines whether an object belongs to a specified class

From left to right

Binocular

7

==

Equals

From left to right

Binocular

Description of the relational operator "= ="

!=

Not equal to

From left to right

Binocular

8

&

Bitwise-AND

From left to right

Binocular

9

|

Bitwise OR

From left to right

Binocular

10

^

Bitwise XOR OR

From left to right

Binocular

11

&&

Short Circuit and

From left to right

Binocular

12

||

Short Circuit or

From left to right

Binocular

13

? :

Conditional operators

From right to left

Tri-Mesh

14

=

Assignment operators

From right to left

Binocular

+=

Mixed assignment operators

-=

*=

/=

%=

&=

|=

^=

<<=

>>=

>>>=

Description

1. Arithmetic operators

+: Addition

-: Subtraction

*: Multiplication

/: Division

%: Take the remainder operation

  2. Relational operators

<: You can only compare relationships between basic types of data, and you cannot compare relationships between objects.

>: (Same relational operator "<")

<=: (Same relational operator "<")

>=: (Same relational operator "<")

= =: If you use this operator to compare references (variables) of two objects, you are essentially comparing two variables that refer to the same object. The so-called same object refers to whether it is an object stored in the same memory unit that was opened up in the stack (heap).

If the contents of the object referenced by the reference (variable) of two objects are compared, the Equals () method should be used, and the return value type of the method is a Boolean value. It is important to note that if you create an object with a class in the class library, the object's reference calls the Equals () method to compare the contents of the object, and if you create the object with a custom class, the object's reference calls the Equals () method to compare whether the two references refer to the same object, because the second case equals The () method defaults to a comparison reference.

! =: (same relational operator "= =")

3, the logical operator (the operator can only be a Boolean type)

&&

||

!

1 public class Demo {2 public     static void Main (string[] args) {3//        System.out.println ((! ') 1 ' | | ' 1 ') +5);//Compile Error 4//        System.out.println (!5);//Compile Error 5//        System.out.println ((' 1 ' | | 1 ') +5);//Compile Error 6//        System.out.println (1| | 2);//Compilation error 7//        System.out.println (5-3| | 4-2);//Compilation Error 8         System.out.println (5<3| | 4>3);//true 9     }10}

  4, bitwise operators

&

|

^

! : cannot be used with = because! is a unary operator; The bitwise non-operation of a Boolean type of data is not possible

5. Shift operators (integer operators only)

Char, Byte, short type, before the shift, will be converted to type int, the result of the shift is also the int type; the operand to the right of the shift symbol intercepts only the last 5 bits of the second binary (the purpose is to prevent the shift operation from exceeding the int type's representation range: 2 5 is 32, The maximum range of type int is 32-bit), the long type is shifted, the result is still long, and the operator to the right of the shift symbol intercepts only the second binary of the latter 6 bits.

<<:

>>: If the sign bit is positive, insert 0 at the highest bit and insert 1 at the highest bit if the sign bit is negative

>>>: Both positive and negative, insert 0 at the highest bit

1 public class Demo {2 public     static void Main (string[] args) {3         //0000 0000 0000 0101 4         //0000 0000 0000 0010 5         System.out.println (5>>1)//2 6         //0000 0000 0000 7         //0000 0000 0000 0100 8         SYSTEM.OUT.P Rintln (8>>1);//4 9         System.out.println (3+5>>1);//410         System.out.println (5>>1);// 511     }12}

Http://www.cnblogs.com/gw811/archive/2012/10/13/2722752.html

Java operator Precedence (RPM)

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.