Java basic data types in bytes

Source: Internet
Author: User

Java basic data types in bytes

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

Boolean: The Size method is not provided;

public class Calcsizof {/** * @param args */private static void calSize() {  System.out.println(Integer:  + Integer.SIZE/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();}}

Running result: console output

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

 

 

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.