Java Program to Find Size of Different Datatype

Problem:- Java Program to Find Size of Different Data type or Find Size of Primitive Data Type in Java or Data types in java with example programs or java Program to Find the Size of int, float, double and char or Java Variables and (Primitive) Data Types or how to find size of variable in java or Find Size of Primitive Data Type in Java or How to find the integer length in java? or size of the variable in java.Write A Java Program To Display Size Of Different Datatype.

Logic:- As we know that C++ has a "sizeof" operator to find a size of any data type or variable. But in Java, we can find the size of a variable by this (Integer.SIZE/8), I want to clear one thing the size of data type maybe depend upon your operating system ( you Are using maybe 32 Bit or 64 Bit ). Below is a syntax of sizeof operator in C++.

Syntax:- sizeof( datatype )

Just replace datatype in above syntax by the following datatype and you are done, size operator displays the size of each variable on the screen.

long double
long long

For Java, the syntax is below you have to only change the datatype but real data type name.



See Also:- C++ Program To Display Size Of Different Datatype

Java Program to Find Size of Different Datatype

import java.util.*;
/* Program By Ghanendra Yadav
 Visit http://www.programmingwithbasics.com/
class SizeofdataTypes
 public static void main (String[] args)
  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.");
Previous Post
Next Post

post written by:

Hi, I’m Ghanendra Yadav, SEO Expert, Professional Blogger, Programmer, and UI Developer. Get a Solution of More Than 500+ Programming Problems, and Practice All Programs in C, C++, and Java Languages. Get a Competitive Website Solution also Ie. Hackerrank Solutions and Geeksforgeeks Solutions. If You Are Interested to Learn a C Programming Language and You Don't Have Experience in Any Programming, You Should Start with a C Programming Language, Read: List of Format Specifiers in C.
Follow Me