Detailed analysis of Java basic types and packages

Source: Internet
Author: User

Java provides eight basic types. Six numeric types (four integers, two floating point types), one character type, and one boolean type.

1. Integer: Contains int, short, byte, long, and the initial value is 0.

2. float: float, double, initial value: 0.0

3. Character: char. The initial value is a space, that is, ''. If the output is not displayed on the Console.

4. boolean: boolean. The initial value is false.

Basic Type Size Minimum value Maximum Value
Boolean ----- ----- ------
Char 16-bit Unicode 0 Unicode 2 ^ 16-1
Byte 8-bit -128 + 127
Short 16-bit -2 ^ 15 + 2 ^ 15-1
Int 32-bit -2 ^ 31 + 2 ^ 31-1
Long 64-bit -2 ^ 63 + 2 ^ 63-1
Float 32-bit IEEE754 IEEE754
Double 64-bit IEEE754 IEEE754
Void      

Note:

The ^ In the table indicates the power of the power;

Java uses unicode, two bytes to represent a character.

Basic Package Type

Integer, Long, Short, Byte, Character, Double, Float, Boolean, BigInteger, BigDecmail

BigInteger and BigDecimal have no corresponding basic types and are mainly used in high-precision operations. BigInteger supports any precision integer,

BigDecimal supports any operation with decimal point precision.

Similarities and differences between basic types and packaging types:

1. in Java, everything is an object, but the eight basic types are not objects.

2. for different declaration methods, the basic type does not need to be created using the new keyword, while the encapsulation type requires the new keyword.

3. for different storage methods and locations, the basic type is to store the values of variables directly in the stack for efficient access. The encapsulation type needs to be referenced to the instance, the specific instance is saved in the heap.

4. Different initial values: the initial value of the encapsulation type is null. The initial value of the basic type depends on the specific type. For example, the initial value of the int type is 0, and the value of the boolean type is false;

5. Use different methods. For example, the packaging type can only be used for cooperation with the collection class.

Related Article

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.