Java Learning Notes-fifth Chapter

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

Fifth chapter Java Operators and expressions

    1. definition: an operator refers to a symbol with an arithmetic function. The data that participates in the operation is called the operand. An expression that consists of an operator and an operand in accordance with certain rules is called a formula.

    2. Classification of operators:

      according to the number of operands different classification: single-mesh operator (unary operator), binocular operator (two-ary operator), trinocular operator (ternary operator)

      according to the nature or use of different classification: arithmetic operators (+ 、-、 *,/,%, + + 、--), relational operators (>, <, >=, <=, = =,! =), logical operators (!, &&, | |), bitwise operators (>>, <<, >>>, &, |, ∧, ~), assignment operators (=, + =,-=, *=,/=,%=, etc.), conditional operators (? And: Paired)

      Arithmetic operators and arithmetic expressions


Classification Operator Name Example Describe

Double

Accounts

Transport

Count

Character

+ Addition A+b A plus B
- Subtraction A-B A minus B
* Multiplication A*b A Times B
/ Division A/b A divided by B
% Take the remainder operation A%b A divided by B takes the remainder

Single

Accounts

Transport

Count

Character

+ Positive sign +a Positive A
- Minus sign -A Negative a
++ Self-increment ++a,a++ A self-add 1
-- Self-reduction --a,a-- A self-minus 1
Integer data when the division (/) operation is performed, the result retains only the integer portion of the value.

The self-increment and decrement operators in the monocular operator are different on the left and right sides of the operands. Difference between the two: when on the left, the operand is increased or reduced by 1 before using the operand; on the right, the operand is used first, and then the operand is increased or self-minus 1.


Relational operators and relational expressions


Operator Name Example Describe
== Equals A==b A equals B?
! = Not equal to A!=b A is not equal to B?
> Greater than A>b A greater than B?
< less than a<b a less than b
>=
greater than or equal to a>=b a is greater than or equal to B
<= Less than or equal A<=b A is less than or equal to B?
the order of operation of the relational expressions is to calculate the values on both sides of the operator first, and then compare the two.


Character data is compared by its position value in the Unicode standard character set. The position values of the common characters are from small to large order: spaces < ' 0 ' <, .... < ' 9 ' < ' a ' <...< ' Z ' < ' a ' <...< ' Z ' < any kanji.


logical operators


Operator Name Example Describe
Logical Non- ! A A is true when the result is false,a to false when the result is true
&& Logic and A&&b True if A and B are true, otherwise false
|| Logical OR a| | B False when A and B are false, otherwise true
Logical XOR or A∧b The result is False if A, B is true or false, otherwise the result is true
"&&" and "| |" Also known as "short-circuit and" and "short-circuit or". If the "&&" left expression evaluates to False, the value of the entire expression is false, and the compiler no longer evaluates to the expression on the right. Similarly, if the "| |" The value of the expression on the left is true, the value of the entire expression is true, and the compiler no longer evaluates to the expression on the right.



assignment operators: The "=" in Java represents an assignment operator, which is different from the equal sign in mathematics (the operator that represents equals in Java is represented by an equal sign ("= =") that is two joined together. For example, an expression a+=b represents a=a+b, meaning a plus B value is assigned to a.


bitwise operators : Bit operators in Java that can operate directly on binary numbers are provided. "~" indicates bitwise negation, "&" means bitwise AND operation, "|" Represents a bitwise OR operation, "∧" is bitwise XOR, "<<" shifts left, ">>" moves to the right, and ">>>" unsigned Right shift.

In order to facilitate the processing of numerical values in the computer system, the values are all in the complement. Where the complement of positive numbers is the same as the original code, the sign bit is 0, for example, +9 of the complement is 00001001, the complement of the negative number is: The sign bit is 1, the remaining digits of the absolute value of the original code is reversed, then the entire number plus 1. For example: for-7来 said, the symbol bit for the 1,+7 of the original code is 0000111 (remove the sign bit, the remaining 7), take the inverse to get 1111000, plus 1 to get 1111001, then 7 of the complement is 11111001.

In the case of no overflow, the left-shift operation is equivalent to the multiplication operation, and the left-shifted n-bit equals the N-time of the operand multiplied by 2, and the right-shift operation is equivalent to the N-bit of the operand divided by 2 by the right shift.


conditional operator:expression1? expression12 :expression13;

the value of the expression expression1 must be Boolean, and the value of the expression ExpressION12 and expression13 can be any type, and the type can be different.

The value of the conditional expression depends on the result of the expression1, and if the expression1 result is true, the expression 2 is executed, otherwise the expression 3 is executed.




Java Learning Notes-fifth Chapter

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.