Java Fundamentals (ii)

Source: Internet
Author: User

Iv. data Types for Java

Basic data type: 8 kinds of Primitive.

1. Integral type

BYTE 1b 8-bit-128 to 127

Short 2b 16-bit -2^15 to (2^15)-1

INT 4b 32-bit -2^31 to (2^31)-1

Long 8b 64-bit -2^63 to (2^63)-1

2, floating-point type

FLOAT 4b 32-bit

Double 8b 64-bit

3. Character type

Char 2b 16-bit

4. Boolean type

Boolean flase/true

Note:

1. Automatic type promotion problem in Java

Forward procedure: From low to high bytes can be automatically converted.

Byte-->short-->int-->long-->float-->double

Reverse process: Convert from high byte to low byte with coercion type.

Note: Reverse conversion will lose precision

2. Boolean: Only True and False

3, Char:java with "\u four hexadecimal digits (even if \u appear in the note, followed by an error if not 4 digits)" means converting characters to their corresponding Unicode encodings, and character types enclosed in single quotes.

4. The default floating-point type has a suffix of "f" or "F" for the Double,float data type.

5. The long type has a suffix of "l" or "L".

Class, interface, array

  Reference type variable name = new reference type name (parameter);//new half followed by the constructor of the class

Member: Written in parentheses inside the body of the class

Automatic type promotion:

BYTE A=1;

BYTE b=2;

A=a+b; Compilation error automatic type promoted to int

A+=b; Z Self-add no automatic type promotion

Type automatic promotion rules:

A and B do some sort of arithmetic:

A and B have double, the result is double

A and B have float, the result is float

A and B have a long, the result is long

In addition, the result is int.

Converting a high byte to a low byte requires a forced type conversion;

byte c= (byte) a+b;

Java Fundamentals (ii)

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.