How to find size of all data types present in JAVA?

How to find size of all data types present in JAVA?



class size
{
        public static void main (String[] args)
        {
                System.out.println("size of integer:"+ (Integer.SIZE/8)+" bytes");
                System.out.println("size of byte   :"+ (Byte.SIZE/8)+" byte");
                System.out.println("size of float  :"+ (Float.SIZE/8)+" bytes");
                System.out.println("size of double :"+ (Double.SIZE/8)+" bytes");
                System.out.println("size of Short  :"+ (Short.SIZE/8)+" bytes");
                System.out.println("size of long   :"+ (Long.SIZE/8)+" bytes");
                System.out.println("size of char   :"+ (Character.SIZE/8)+" bytes");
        }
}

// We are divding it by 8 because it give the output in bits and we need in bytes.


Output:
size of integer:4 bytes
size of byte   :1 byte
size of float  :4 bytes
size of double :8 bytes
size of Short  :2 bytes
size of long   :8 bytes
size of char   :2 bytes
How to find size of all data types present in JAVA? How to find size of all data types present in JAVA? Reviewed by Unknown on January 28, 2019 Rating: 5

No comments:

If you have any doubt or query ,comment below:

Programming copyright © 2018-19. Powered by Blogger.