Explanations of commonly used operators and expressions in the Java language

Source: Internet
Author: User
Tags arithmetic operators bitwise bitwise operators float double logical operators

Java provides rich operators, such as arithmetic operators, relational operators, logical operators, bitwise operators, and so on. an expression in Java is a Java-compliant formula that is concatenated with operators . The precedence of an operator determines the order in which operations are performed in an expression. Use parentheses () as much as possible when writing programs to achieve the desired order of operations, so as not to produce difficult-to-read or ambiguous calculations. The binding of operators determines the order of the same-level operators in parallel.

Arithmetic operators

1. Add and Subtract Operators : +,-

The add-minus operator is a two-mesh operator, and the plus-minus operator is bound from left to right, the operand of the decrement operator is integer or float data, and the decrement operator has a priority of level 4 .

2. Multiply, divide, and seek remainder operators: *,/,%

The above operator is a two-mesh operator, with a combination of a left-to-right, multiply, divide, and balance operators that are integer or float data. The precedence of the operator is level 3.

3. An arithmetic expression

A formula that is concatenated with arithmetic symbols and parentheses that conforms to the rules of Java syntax, called an arithmetic expression

4. Self-increment decrement operator:+ +,--

is the monocular operator, which can be placed before an operand, or after an action element. The operand must be an integral or floating-point variable. The effect is to increase the value of the variable by 1 or minus 1, for example:

++x(--x) means that the value of x is increased (minus)by1 before using x .

x + +(x--) indicates that the value of x is increased (minus)by1 after using x.

Operation Accuracy

The order in which precision is arranged from "Low" to "high" is:

byte short char int long float double

when Java computes the value of an arithmetic expression, the following calculation precision rules are used:

1. If there is a double-precision floating-point number ( double -type data) in the expression, the operation is performed by double precision.

2. If the highest precision in an expression is a single-precision floating-point number (float data), the operation is done by single precision.

3. If the highest precision in an expression is a long Integer, the operation is performed by a long precision.

4. If the highest precision in an expression is lower than an int , the operation is performed by int precision.

Relational operators

A relational operator is a two-mesh operator that is used to compare a relationship of two values. The operation result of the relational operator is Boolean, and the result of the operation is true if the operator corresponds to a relationship,otherwise false.

logical operators

logical operators include:&&,| | , !

where &&,| | is a two-mesh operator , implement logical and logical OR.

! Implements logical non for single-mesh operators.

the operand of a logical operator must be a boolean data that can be used to concatenate a relational expression.

Bitwise operators

in the actual less Java bitwise operators are used

Two integer data implementation bit operation, that is, two integer data corresponding to the bit to operate to obtain a new integer data.

1. Bitwise AND Operation

The bitwise AND operator&is a two-mesh operator.

2. Bitwise OR "Operation

Bitwise OR operator: "| "is a two-mesh operator.

3. Bitwise NOT "Operation

The bitwise NON operator: "~" is the monocular operator.

4. Bitwise XOR Operation

Bitwise XOR Operator: "^" is a two-mesh operator.

Other

1. Assignment operators and Assignment expressions:=

The assignment operator is a two-mesh operator, and the action element on the left must be a variable, not a constant or an expression.

the assignment operator has a lower priority, which is a combination of a right-to-left direction.

The value of an assignment expression is thevalue of the left variable of "=".

Note: Do not confuse the assignment operator "=" with the relational operator "= =".

2.instanceof operator

The instanceof operator is a two-mesh operator, and the action element on the left is an object, and the right is a class. When the object on the left is the object created by the right-side class or subclass, the result of the operator operation is true , otherwise false.  

original link:http://www.maiziedu.com/wiki/java/operator/

Explanations of commonly used operators and expressions in the Java language

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.