Length of type in Java

Source: Internet
Author: User

Introduced:

There are 8 basic types in Java, namely, Boolean, Char, Byte, short, int, long, float, double. Their lengths are fixed, not objects. For situations where it is necessary to treat a base type as an object, Java provides a wrapper class, which has the advantage that the Java compiler and the runtime are easier to optimize. Because of Java portability, each type is the same size on different platforms.

Code implementation:

 PackageSelf ;/*** Created by Jimmy on 2015/5/18.*/ Public classsizeof { Public Static voidMain (string[] args) {System.out.println ("Integer:" + INTEGER.SIZE/8);//4System.out.println ("Short:" + SHORT.SIZE/8);//2System.out.println ("Long:" + LONG.SIZE/8);//8System.out.println ("Byte:" + BYTE.SIZE/8);//1System.out.println ("Character:" + CHARACTER.SIZE/8);//2System.out.println ("Float:" + FLOAT.SIZE/8);//4System.out.println ("Double:" + DOUBLE.SIZE/8);//8//System.out.println ("Boolean:" + BOOLEAN.SIZE/8); //True/false    }}

Output:

1 integer:42 short:23 long:84 byte:15 character:26 float:4  7 Double:8

Length of type in 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.