Java programming thought Note Chapter III operator

Source: Internet
Author: User

1. Type of operator:

Order of Operations 1-7

1.1 Unary operator (monocular operator)-minus, + plus sign,--decrement, + + increment

1.2 Arithmetic operator +-*/%

1.3 shift operator << left shift (low 0),>> right (negative high 1, positive high 0),

>>> Unsigned Right shift (whether plus or minus 0) (binary)

(Can be used in conjunction with = <<= >>= >>>= similar i + = 1) shift operator detailed

1.4 Relational Operators > < >= <= = = = = (generates a Boolean value)

1.5 Logic Operators && | | ! (Generates a Boolean value)

1.6 Bitwise Operators & | or ^ Xor ~ non (unary) (binary)

1.7 Ternary operator

Boolean //
2. prefix and suffix type

2.1 Prefix--+ + as-I; ++i; First, I perform the -1,+1, then assign to I then perform the subsequent operation;

2.2 Suffix--+ + as i--; i++; Operation (i--) immediately after the end of the I-1 +1;

2.3 Suffix There is a trap is i = i++, this code has pits, I will not self-increment,

 int  s = 1;  int  i = s++ * 3; System.out.println (s);  // 2  System.out.println (i); // 3  s = 1;i  = ++s * 3 ; System.out.println (s);  // 2  System.out.println (i); // 6  s = 1;i  = s++ + (S * 3); System.out.println (s);  // 2  System.out.println (i); // 7  

2.4 Due to the different position of the suffix in the expression, the result of the calculation is different

int g = 5;               // expression G + (g++ + g) loaded from left to right in memory, calculated by priority int i = g + (g++ + g);  // The first g=5, g++ is 5, the last G is 6, the first G is 5 when the data is loaded into memory, and after the load is completed g++, then the G is 6. System.out.println (i); // g = 5= g++ + (g + g); // g++ is 5 and the two G is 6 . System.out.println (i); //  -

3. Aliasing: Different references point to the same object 4. Random number generation
New Random ();         int k = rand.nextint (+);         int // 0.0~1.0 the number of digits is not necessarily

4.1 When you create a random object, there is no parameter (seed) passed in, and the current time is passed as the seed of the random number generator

4.2 For the same seed will have the same random number sequence, the current time constantly in the variable random number sequence is also different

4.3 Generate different types of random numbers call the corresponding method can be

The parameter of the 4.4 Nextint () method determines the upper limit of the random number, and also determines the lower bound 0, which is +1 when the divisor is made.

5. Short Circuit:
    • The rest of the expression is no longer evaluated when using logical operators for example: Test1 () && test2 () && test3 ();
    • If Test1 () is first computed as false, then false && Test2 is definitely not executed for False,test2 (), "False && Test2" is false test3 () will not execute if && has become a | | Then we have to execute test3 ().
6. Direct constant Specification
    • float or float assigns an initial value when using L such as float f = 2L; Double plus d or d,16 prefix 0X, 8 binary prefix o
7. Type conversion details between basic data

7.1 Byte,short,char operation will promote the result to int

7.2 Type Auto Lift small range type + Large range type = Large range type (byte,short,char) int long float double increment

7.3 char c = ' A ' turn integer will be converted to corresponding ASCII value, char c = 98 Turn string will be converted to corresponding character

7.4 float, double to integer direct end, not rounded, rounded using the round () method in Java.lang.Math.

8. Data type

Java programming thought Note Chapter III operator

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.