A simple explanation of the automatic packing and unpacking of Java

Source: Internet
Author: User

Boxing is the encapsulation of the underlying type into a class. For example, when an int is encapsulated into an integer, then you can't think of him as a number, but a class, and the way to do it is to use it.

Unpacking is the conversion of a class to an underlying type. For example, you calculate an addition what is not to use the class, you have to convert it into a basic type,Jdk5 can be converted automatically after the seemingly. Basic types you should know that.

(Byte,short,int,long,float,double,boolean,char)

Byte:java.lang.Byteshort:java.lang.Shortint:java.lang.Integerlong:java.lang.Longfloat:java.lang.Floatdouble : Java.lang.Doublechar:java.lang.Characterboolean:java.lang.Boolean In addition, there are two commonly used packaging classes: BigInteger and BigDecimal in addition, By the way, the basic type of Java occupies the number of bits: 1 bytes is 8 bits, that is, 8bit, note that a byte 8 bits and language independent AH only 8 basic types can be counted. Other reference types are determined by the Java Virtual machine itself cannot manipulate byte 1 bytes short 2 byte int 4 byte long 8 bytes Float 4 byte double 8 byte char 2 byte Boolean 1 byte

  

A simple explanation of the automatic packing and unpacking of Java

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.