Java program to find the size of primitive data types
KW.java
class KW
{
    public static void main(String args[])
    {
        System.out.println("———————————————————————————————————————————");
        System.out.println("Program to find the size of data types");
        System.out.println("———————————————————————————————————————————");
        System.out.println("Size of byte   | "+(Byte.SIZE/8)+" byte");
        System.out.println("Size of short  | "+(Short.SIZE/8)+" bytes");
        System.out.println("Size of int    | "+(Integer.SIZE/8)+" bytes");
        System.out.println("Size of long   | "+(Long.SIZE/8)+" bytes");
        System.out.println("Size of char   | "+(Character.SIZE/8)+" bytes");
        System.out.println("Size of float  | "+(Float.SIZE/8)+" bytes");
        System.out.println("Size of double | "+(Double.SIZE/8)+" bytes");
        System.out.println("———————————————————————————————————————————");
    }
}
Output
kodingwindow@kw:~$ javac KW.java
kodingwindow@kw:~$ java KW ——————————————————————————————————————————— Program to find the size of data types ——————————————————————————————————————————— Size of byte | 1 byte Size of short | 2 bytes Size of int | 4 bytes Size of long | 8 bytes Size of char | 2 bytes Size of float | 4 bytes Size of double | 8 bytes ——————————————————————————————————————————— kodingwindow@kw:~$
Advertisement