Summary of Java data types and data type conversion issues

Source: Internet
Author: User
Tags float double

(1) Summary of data types

Java data types are mainly Boolean, byte, int, short, char, long, float, double.

The byte type data occupies 1 bytes, 8 bits, and the highest bit represents the symbol, then the range is: -2^7~2^7-1

The int type data is 4 bytes, a total of 32 bits, the highest bit represents the symbol, then the range is: -2^31~2^31-1

The short type data occupies 2 bytes, a total of 16 bits, the highest bit represents the symbol, then the range is: -2^15~2^15-1

The long type data is 8 bytes, a total of 64 bits, and the highest bit represents the symbol, the range is: -2^63~2^63-1

The float data type occupies 4 bytes, a total of 32 bits, the range is: 10^-38~10^38 and -10^38~-10^-38

The double data type is 8 bytes, a total of 64 bits, and the range is: 10^-308~10^308 and -10^308~-10^-308

The char data type occupies 2 bytes, but the highest bit is not used to represent the symbol. Then it can represent the character of the 0~2^16-1 (0~65535) position in the Unicode set.

The char data type is applied in the following ways:

such as: Char a= ' a '; Char a=97 (cannot use the short type, because the highest bit represents the symbol, so the value is only 15 bits);

(2) data type conversion issues

Data types have precision, from low to high sort: byte short int long float double

When a variable of a low precision type assigns a value to a high-precision variable, it can be assigned directly, such as:

float a=100; output A is 100.0

When high-precision variables are assigned values to low-precision variables, display conversions must be performed, such as:

int a= (int) 123.345f;

The above is a personal learning harvest, if there are errors, please correct me.

Summary of Java data types and data type conversion issues

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.