Number of bytes in Java for each basic data type

Source: Internet
Author: User

Int:4 bytes
Short:2 bytes
Long:8 bytes
Byte:1 bytes
Character:2 bytes
Float:4 bytes
Double:8 bytes

Boolean: The system does not provide a size method;

public class Calcsizof {/** * @param args */private static void Calsize () {  System.out.println ("Integer:" + INTEGER.S IZE/8);           4  System.out.println ("short:" + SHORT.SIZE/8);               2      System.out.println ("Long:" + long.size/8);                 8  System.out.println ("Byte:" + byte.size/8);                 1  System.out.println ("Character:" + character.size/8);       2  System.out.println ("Float:" + float.size/8);               4  System.out.println ("Double:" + double.size/8);             8  System.out.println ("Boolean:" + boolean.tostring (false));  } public static void Main (string[] args) {//TODO auto-generated method stubcalcsizof calcsizof= new Calcsizof (); Calcsizof.calsize ();}}

Operation Result: Console output

Integer:4
Short:2
Long:8
Byte:1
Character:2
Float:4
Double:8
Boolean:false

For more information on the footprint of the encapsulated object, please refer to

http://blog.csdn.net/ithomer/article/details/7310008

Number of bytes in Java for each basic 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.