Basic types in Java consume bytes

Source: Internet
Author: User

Due to the limitations of mobile device memory in mobile development, it is often necessary to consider the number of bytes consumed by the data type used. Below is a brief introduction to some basic data types in Java to deepen your memory.
There are 8 basic data types in Java, including 4 integers, 2 floating-point types, 1 character types used to represent Unicode-encoded character cells, and 1 Boolean types that represent truth values. (one byte equals 8 bit)

1. Integral type
Type storage requirement bit number value range remark
int 4 byte 4*8
Short 2 byte 2*8-32768~32767
Long 8 byte 8*8
BYTE 1 byte 1*8-128~127

2. Floating-point type
Type storage requirement bit number value range remark
Float 4 byte 4*8 float type has a suffix f (for example: 3.14F)
Double 8 byte 8*8 floating-point value with no suffix f (for example, 3.14) defaults to double type

3.char type
Type storage Requirements
Char English byte, Chinese 2 bytes (not necessarily under other encodings)

4.boolean type
Type storage requirement bit number value range remark
Boolean 1 byte 1*8 false, True

Add: Java has a schoolbag that can represent any precision, often called a "big number". Although it is called a large value, it is not a Java type, but a Java object.

If the basic integer and floating-point precision are not sufficient, then two useful classes in the Java.math package can be used: Bigintegerbigdecimal (also included in the Android SDK Java.math package and these two classes) These two classes can handle numeric values that contain a sequence of arbitrary lengths. The BigInteger class realizes the integer operation of arbitrary precision, and BigDecimal realizes the floating-point number operation with arbitrary precision. Specific usage can be found in the Java API.

Basic types in Java consume bytes

Related Article

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.