Java Basic program Design structure "3"

Source: Internet
Author: User

Data type

  In Java, there are 8 basic types (primitive type), with 4 integer ,2 floating-point types , and1 character types used to represent Unicode-encoded character cells Char and 1 boolean types that are used to represent truth values (Boolean types).

  1. Integral type

Type Storage requirements Range of values
Int 4 bytes -2 147 483 648 ~ 2 147 483 647 (just over 2 billion)
Short 2 bytes -32 768 ~ 32 767
Long 8 bytes -9 223 372 036 854 775 808 ~ 9 223 372 036 854 775 807
Byte 1 bytes -128 ~ 127

  The long integer value has a suffix of L(e.g. 4000000000L). The hexadecimal value has a prefix of 0x(such as 0xCAFE). Octal has a prefix of 0, in order to avoid confusion, as little as possible with the octal system.

Note that Java does not have any unsigned type (unsigned).

2. Floating-point types

Type Storage requirements Range of values
Float 4 bytes Approx. ±3.402 823 47E + 38F (6 to 7 digits of effective digits)
Double 8 bytes Approximately ±1.797 693 134 862 315 70E + 308 (valid digits are 15 bits)

  A value of type float has a suffix f (for example, 3.14F). A floating-point value with no suffix f (such as 3.14) defaults to the double type. Of course, you can also add a suffix D after a floating-point value (for example, 3.14D).

  All floating-point numeric calculations follow the IEEE 754 specification. The following are three special floating-point values used to represent overflow and error conditions:

Zheng Infinity
Negative infinity
NaN (not a number)

  3.char type

  The char type is used to represent a single character. Typically used to denote character constants. For example: ' A ' is a character constant encoded as 65. Unlike "a", "a" is a string that contains the character a. Unicode encoding units can be represented as hexadecimal values, ranging from \u0000 to \UFFFF. For example: \u2122 represents a registration symbol (TM), and \u03c0 represents the Greek letter p.

In addition to the escape sequence character \u, which represents the encoding of a Unicode code unit, there are also escape sequence characters for special characters, see table 3-3. All of these escape sequence characters can appear in a character constant or in the quotation marks of a string. For example, ' \u2122 ' or ' hello\n '. The escape sequence character \u can also appear outside the character constant or the quotation marks of a string (while all other escape sequences may not).

  4.Boolean type

  A Boolean(Boolean) type has two values: false and True, which are used to determine the logical condition. an integer value and a Boolean value cannot be converted to and from each other .

Java Basic program Design structure "3"

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.