Java program to find the size of primitive data types
GD.java
classGD{publicstaticvoidmain(Stringargs[]){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
godarda@gd:~$ javac GD.java godarda@gd:~$ java GD
———————————————————————————————————————————
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
———————————————————————————————————————————
godarda@gd:~$
Dear User, Thank you for visitng GoDarda. If you are interested in technical articles, latest technologies, and our journey further, please follow us on LinkedIn.