Java Data types

Source: Internet
Author: User

Java is a strongly typed language.

Java has a total of 8 basic types, of which 4 are shaped, 2 floating-point types, 1 are used to represent Unicode-encoded character cells, char and 1 are used to represent true and false Boolean types.

integer : In Java, the scope of the shaping is independent of the machine running Java code--addressing cross-platform, different-digit operating system issues.

Int:4 byte -2147483648~2147483647 ( just over 2 billion )

Short:2 bytes -32768~32767

Long:8 byte Very Large

Byte:1 bytes -128~127

1 normally the int is sufficient.

2 Long integer has a suffix l

3 Note Java does not have any unsigned type (unsigned type)

float type : float 4 bytes

Double 8 bytes

1 in most cases the double type is used, and the precision of the float type is difficult to meet

2 float type suffix f

3 floating-point value without suffix f (for example, 3.402) defaults to double type

4 Double type suffix D

Interesting thing: System.out.println (2.0-1.1); will print 0.8999999999999999 instead of 0.9 of people's imagination. The main reason is that the floating-point value is represented by a binary system, and the fractional 1/10 is not accurately represented in the binary system. So you need to use the BigDecimal class without error.

Java Data types

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.