Data type Java

Source: Internet
Author: User

Java takes up the number of bytes
Data type size (number of binary digits) range Default value

Byte (bytes) 8-128-127 0
Shot (short-integer) 16-32768-32768 0
int (integral type) 32-2147483648-2147483648 0
Long (length) 64-9233372036854477808-9233372036854477808 0
Float (float type) 32-3.40292347e+38-3.40292347e+38 0.0f
Double (dual precision) 64-1.79769313486231570e+308-1.79769313486231570e+308 0.0d
char (character type) + ' \U0000-U\FFFF ' ' \u0000 '
Boolean (Boolean)      1                   true/false                                                                                                 false


What is the number of bytes in the Java base data type? BYTE 1 byte short 2 byte int 4 byte long 8 byte char 2 byte (C The language is 1 bytes) can store a Chinese character float 4 byte double 8 byte Boolean false/true (theoretically occupies 1bit,1/8 bytes, actual processing by 1byte processing)
Java is encoded using Unicode. Each byte occupies 8 bits. Your computer system should be a 32-bit system, so that each int is 4 bytes
One of these bytes consists of 8 bits

There are altogether 8 basic data types in Java (raw data types):     
Type storage requirements range (inclusive) default wrapper class
Integer int 4 bytes (32 bits) -231~ 231-1 0 Integer
Number short 2 bytes (16 bit) -215~215-1 0 short
Class Long 8-byte (64-bit) -263~263-1 0 long
Type byte 1 byte (8 bit) -27~27-1 0 byte
float Float 4 byte (32 bit) -3.4e+38 ~ 3.4e+38 0.0f Float
Type Double 8-byte (64-bit) -1.7e+308 ~ 1.7e+308 0 Double
Character Char 2-byte (16-bit) u0000~uffff (' ~ '? ' 0 ' Character
(0~216-1 (65535))
Boolean boolean 1/8 bytes (1 bits) True, False False Boolean
int is typically 4 bytes, which is related to the operating system.
Turbo C (and some of the turbo C derivative compilers, they use a set of compiler program) is the DOS era of the compiler, is the product of the 80 's, seriously outdated, belongs to the old product, they compiled the program is 16-bit operating system DOS program, so the length of 16 bits, That is, two bytes. Windows is compatible with DOS, so the files generated by the Turbo C can also be run in Windows.
The others are usually 4 bytes.
Operating system 16-bit, int 2 bytes, operating system 32-bit, int 4 bytes, because 32-bit system before the dominant position, actually now is a 64-bit system, for compatibility considerations, int is also 4 bytes


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 requirement bit number value range remark
Char 2 byte 2*8

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.

Data type Java

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.