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