Java, data type

Source: Internet
Author: User

Data types determine how data is stored and how it is operated

Integer type:

Java each integer type has a fixed number of table range and field length, not affected by the specific operating system, to ensure the portability of Java programs

Constant:

three representations of integer constants:

? decimal integer, such as 12,-314, 0.
An octal integer that requires starting with 0, such as 012
Hexadecimal number, which requires 0x or 0X, such as 0x12
Binary number, beginning with 0b or 0 B, such as 0b00010010 (JAVA7 or more)

1. The default is int type

2. Declare a long constant can be followed by ' l ' or ' l ', such as: long L = 3L.

3. There is no "unsigned number" in Java, you can use long to process unsigned integers (UINT)

Floating-point types:

Constant:

Two types of representations:

The decimal number form must contain a decimal point, for example: 3.14 314.0.314 Java7 Above: 123_456.789_000 (the thousand-bit separator is underlined)

  scientific notation forms, such as 3.14e2 3.14E2

1. The Java floating-point constant defaults to double type,

2. To declare a constant of type float, add F or F after the number, such as float f = 3.14f;

Character type:

1. Java characters are Unicode encoded with two bytes per character

Can be expressed in hexadecimal encoded form
char c1 = ' \u0061 ';

2. Character constants are single characters enclosed in single quotes
char c = ' A ';

3. Escape character ' \ '

char c2 = ' \ n '; Represents a newline character.

Boolean type:

Boolean data only allows values of true or FALSE, and cannot replace true and false with integers of 0 or not 0

The difference:

Boolean true //  //  declare int variable float//  declare float type variable and assign double//  declares a double variable and assigns the value char// declares a char-type variable c = ' \u0031 '; // Assigning a value to a char type variable // Assigning a value to an int type variable

Java, data type

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.