Friday, 23 December 2016

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.

int
float
double
long double
long long


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

(datatype.size/8)


(Integer.SIZE/8)
(Long.SIZE/8)
(Character.SIZE/8)
(Float.SIZE/8)
(Double.SIZE/8)


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.");
  }
}

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date. If you have any Query or Question you can ask in the group, I will Try To Solve your Query and try to answers of your Questions withing 24 Hours, You can also Email me or comment below Please suggest to your Friends to join and like our page and don't forget to Subscribe. Enter your Email and click to subscribe.

Ghanendra Yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

No comments:

Post a Comment