What data types are available in Java? Number of bytes per base data type

Source: Internet
Author: User

Java data types are divided into: basic data types and reference data types.

Number of bytes for the base data type:

Data type Bytes Default value
Byte 1 0
Short 2 0
Int 4 0
Long 8 0
Float 4 0.0f
Double 8 0.0d
Char 2 ' \u0000 '
Boolean 4 False

With regard to the Boolean account of a few bytes, there is a divergence of opinions, although Boolean shows a "bit" attribute that is not 0 or 1, but the basic unit of measurement for storage space is bytes, not bits. So the Boolean accounts for at least 1 bytes.
In the JVM specification, a Boolean variable is treated as an int, which is 4 bytes, whereas a Boolean array is treated as a byte array, that is, a Boolean in the boolean array is 1 bytes.

What data types are available in Java? Number of bytes per base data type

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.