Java Learning: Operators and Precedence

Source: Internet
Author: User
Tags bitwise

Operator

    • Separator: ,; [] ()
    • Arithmetic operator: +-*/% + +--
    • Relational operators: > < >= <= = = =!
    • Logical operator: !  & | ^ && | |
    • Assignment operator: =
    • Extended assignment Operator: + = = *=/=
    • Trinocular operator: ?:
    • String Join operator: +

The "+" and "-" operators can also be used as positive and negative symbols of the data.

&&: Short circuit and, as long as one of the expressions or methods has a value of false, the result is false and the subsequent operation is not performed.

|| : Short-circuiting or, as long as one of the expressions or methods has a value of true, the result is true and the subsequent operation is not performed.

 Short s = ten; // error, S is short,1 default to int, first convert right s to int and add, result int // s = s + 1;     // error s = (short) (s + 1);    // correct s + = 1;        // correct, equal to S = (short) (S + 1);

Three-mesh operators:

X? Y:z x is a Boolean type, and if X is true, the expression result is Y, otherwise Z

String connector: As long as "+" appears on either side of the string, "+" represents the string connector

    • The operator "+" is used for numeric type data, which is an addition operator

Example: "Abd" + "de" Result: "ABCDE"

    • Used for string Lee type, which is a connector
    • string + numeric value, Java automatically converts the value to a string and then joins it into a new string

Example: "12" + 34 Result: "1234"

System.out.println (12+34+ "");    // " the" System.out.println ("+12+34");    // "1234"

Precedence of Operators

    • In addition to the Monocular operator, assignment operator, and conditional operator, the other operators are combined from left to right.
    • Operator Precedence formula: non-, count, close, and OR, assign
    • The following table is priority order, high priority in upper, same row priority
Operator Precedence Upgrade

Operator description

Java operators

Separator

. []  ()  ,  ;

Monocular operator

+-~! + +--

Create or type conversions

New (Type)

Multiplication/Division

*  /  %

Addition/Subtraction

+

Relationship

< <= >= > instanceof
Equivalent

= = =

Bitwise-AND

&
Bitwise XOR OR

^

Bitwise OR

|

Conditions and

&&

Conditions or

||

Conditions

? :
Assign value

=

Java Learning: Operators and Precedence

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.