Java Basic Types

Source: Internet
Author: User

---restore content starts---

Type

Basic type
Types of Java
Reference type


Basic type

shaping (Byte, short, int, long)
floating-point type (float, double)
character Type (char)
Boolean Type (Boolean)


Plastic
Bit (bit): either 0 or 1
Byte (byte): 8 bit.

2^0 2^4=>16 2^5=>32 2^6=>64 2^7=>128 2^8=>256 2^9=>512 2^10=>1024 (K)
2^11=>2048 2^12=>4096 2^16=>65536 2^20=>m 2^30=>g (1 billion) 2^40=>t


Byte:8 bit (can represent 256 numbers), Value range: -128~127
Short:16 bit (can represent 65,536 numbers), Value range: -32768~32767
Int:32 bit (can represent 4G number), Value range: -2g~2g-1
Long:64 bit (large range of values, no memory required)

Note the point:
A, you directly give an integer, the integer default is the int type.
If the integer value is small, and is directly assigned to byte or short, Java can also treat it as a byte and a little bit.

B, if you give a huge integer directly, Java does not automatically treat it as a long type.
If you want Java to treat the integer as long, you need to add L or L after the integer.

C, Integer A total of 4 forms of expression:

Decimal:
Octal: Starting with 0
Every 8 in 1, can only appear 0~7.
Hex: Starts with 0 x or 0x.
Every 16 into 1, can only appear 0~9, a~f.
Binary: Starts with 0 B or 0b
Every 2 in 1, can only appear 0~1

Hexadecimal numbers, which are very common in programming--each hexadecimal number is exactly converted to a 4-bit binary number, so it's very handy

---restore content ends---

Java Basic Types

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.