Java Day 03

Source: Internet
Author: User

Comparison Operators & logical operators
> >= = = < <=! = instanceof

& && | | | ^ ! Logical operators are used to concatenate expressions of two Boolean types
X>2 & X<5
True & true = True
False | False = False

^ xor (different or operation) the same is false, the difference is true.
! Non-operational

Bitwise operators
<< >> >>> (unsigned Right shift) & | ^ ~ (anti-code)
6 & 3 = 2//
6 | 3 = 7//
6 ^ 3 ^ 3 = 6

Shift Operations
3 << 2 = 3 * 2 * 2 = 12//left shift equals several powers multiplied by 2
6 >> 1 = 6/2 = 3//The highest bit is what it takes to fill a bit
>>>//The highest bit in the right shift is 0

Fast calculation 2*8 2<<3
Two integer value swaps
1. Temporary variables
2, a=a+b;b=a-b;a=a-b;//if and more than int range, will cast
A=a^b;b=a^b;a=a^b;

Ternary operators
(conditional expression)? Expression 1 (True): Expression 2 (False)

If
1. A branch
2, two branches//equal to the ternary operator, if the IfElse does not have a result can not be simplified into ternary operators
3. Multiple branches
Nearest principle

If nesting

Local code block
Variable initialization scope

Switch statement
switch (expression) {//Expression int short byte char
Case takes value 1:
Statement 1;
Break
...
Default
Statement
Break
}//case unordered default execution; the break of the last case can be omitted; other break omitted;

If and switch differences
If 1, the specific value of judgment, 2, interval judgment; 3. The result of the operation of the expression is a Boolean
Switch 1, the specific value of the judgment, 2, the number of fixed value, all the answers into memory, high efficiency;

While, do and for
while (conditional expression) {
Execute the statement;
}

do{
Execute the statement;
}while (conditional expression);

Accumulation

Counter

For statement
For (initialization expression 1; loop condition expression 2; post-loop action expression 4) {

Execute statement; (Loop body) 3

}

For and while differences
1, can be interchanged
2, the variable of the loop, the scope is different

Infinite loop form
while (true) {}
for (;;) { }

Java Day 03

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.