Basic data types for Java and some operators

Source: Internet
Author: User

1 integer type
Byte accounted for 1 bytes (1 bytes in memory 8 bits
Short takes 2 bytes
int accounted for 4 bytes
Long takes 8 bytes


2 floating-point type
Float takes 4 bytes
Double takes 8 bytes


3 Character type
Char is 2 bytes, character data is 16-bit unsigned integer data, which represents the Unicode set, the range is 0~65535


4. Left shift operator (<<)
The result of the shift is that the left operand is multiplied by the power of 2, and the exponent value is given by the operand on the right.
For example: 128<<1 equals 128*2=256 (left multiply right divide)


5. "Signed" Right shift operator
Symbol extension used: If the sign bit is positive, insert 0 in the high position, and if the sign bit is negative, insert 1 at the high.
For example: 128>>1 equals 128/2=64 (left multiply right divide)


6 "Unsigned" right-shift operator (>>>)
"0 Expansion": both positive and negative, are inserted in the high 0


7 Left Shift assignment operator (<<=)
The left side of the operator shifts the number of digits specified by the value to the left and then assigns the result to the left


8 Right Shift assignment operator (>>=) Ibid.


9 Unsigned Right Shift assignment operator (>>>=) Ibid.
Note: When you perform an unsigned right-shift assignment operation, you may encounter a problem: If you do such a shift operation on a byte or short value, you may not get the correct result, they may be converted to type int and then right-shifted, but the "0 extension" (see 6 above) does not occur. So in this case you get the result of-1.

Basic data types for Java and some operators

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.