• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

int data type takes 4 bytes

 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hai
int data type take 4 byte.

we can display max and min range of integer as
System.out.println(Integer.MAX_VALUE);
System.out.println(Integer.MIN_VALUE);

then
int i=10;

i want to print how many bytes for (int i=10) is allocated.
in C language we have sizeof() function to print.
Is there any method in java to print it.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No. Java abstracts away that kind of low-level detail.
 
Ranch Hand
Posts: 694
Mac OS X Eclipse IDE Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In Java, there is no need for a sizeof operator because in Java types are always the same size:

byte is always 1 byte
short is always 2 bytes
int is always 4 bytes
long is always 8 bytes

etc.

Kaydell
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All that Java guarantees is that an int is 32 bits (4 bytes), so that you can store integer numbers with values between -2^31 and 2^31 - 1 in it.

If the JVM which you are using actually uses 4 bytes of memory, is something you don't know. On some computers it might for example take 64 bits because that's more efficient on that specific type of computer. However, if the JVM behind the scenes uses 64 bits, that doesn't mean you can suddenly store larger numbers in an int.

From the Java programmer's perspective, an int is always 32 bits. But how the JVM handles ints under water might be different.
[ August 02, 2007: Message edited by: Jesper Young ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic