Java data types and corresponding value ranges

Source: Internet
Author: User

Java data types and corresponding value ranges

In Java, data types fall into two categories: basic data types (value types) and wrapper types (reference data types). The base data type is not an object, and methods such as ToString (), Hashcode (), GetClass (), Equals () cannot be called.

8 Basic data Types-----8 Types of packaging

Integral type :

byte byte "-128,127" 1 bytes ("-2 7, 2 7") One byte has 1 bits

Short short " -32768,32767" 2 bytes ("-2 15-square, 2 15-square-1") 2*8-1

int Integer " -2147483648,2147483647" 4 bytes ("-2 of 31-square, 2 31-square-1") 4*8-1

Long Long " -9223372036854774808,9223372036854774807" 8 bytes ("-2 of 63 times, 2 63") 8*8-1

You can see that the value range of byte and short is small, and Long's range is too large, occupy more space, basically int can meet our daily calculations, and int is the most used integer type.
In general, if there is an integer number such as 35 in Java, then this number is the int type, if we want it to be a byte type, we can add the uppercase b:35b after the data, indicating that it is byte type, the same 35S means short type, 35L means long, which means int we can do nothing, but if you want to represent a long type, be sure to add "L" after the data.

floating point type :

Float Float 4 bytes

Double Double 8 bytes

The difference between them is that their accuracy is different .

Double type more than float type storage range, more accurate, so the usual floating-point data is not declared in the case of double type, if you want to indicate that a data is float type, you can add "F" after the data.
The floating-point data is not completely accurate, so sometimes it is normal to have floating in the last few decimal places when calculating.

Character type :

Char Character 2 bytes

The data type used to hold characters, 2 bytes, Unicode encoded, and ASCII compatible with the first 128 bytes of encoding
Characters are stored in \u0000~\uffff, when defining character-type data, be careful to add ' ', such as ' 1 ' for the character ' 1 ' instead of the value 1

Boolean type :

Boolean Boolean

Only two values, true and False

Note: This article is from Web page replication.

Java data types and corresponding value ranges

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.