• Tutorials
  • DSA
  • Data Science
  • Web Tech
  • Courses
July 24, 2022 |19.3K Views

Java Program to Find Size of int, float, double and char in your system

  Share  1 Like
Description
Discussion

In this video, we will see how to check a size of data types (char, int, float, etc) in Java. 

Sizeof() is an important operator in C and C++. Basically, it is a compile-time unary operator which can be used to compute the size of its operand. The result of sizeof is of the unsigned integral type which is mainly denoted by size_t. 

The sizeof() can be applied to any kind of data type, including primitive types i.e integer types, floating-point types, pointer types, or compound data types such as Structure, union, etc. When sizeof() is used with the data types such as int, float, char etc. It simply returns the amount of memory allocated to that data type.

But in the case of Java, there is no sizeof() operator, we need to calculate the size using the wrapper class using datatype.SIZE and then divide it by 8 to convert it into bytes format. Here we use wrapper classes to find the size of the data type in JAVA.

Java program to get size of data types:
https://www.geeksforgeeks.org/how-to-get-size-minimum-and-maximum-value-of-data-types-in-java/