size of int in java
843829Jun 22 2009 — edited Jun 24 2009Hi,
From the java textbooks I understand that the size of primitive types are fixed in java irrespective of the underlying OS and architecture, but recently I went through some articles which left me a bit confused.
Here are the snippets -
http://www.artima.com/insidejvm/ed2/jvm3.html
An implementation designer must therefore choose a word size that is at least 32 bits, but otherwise can pick whatever word size will yield the most efficient implementation. The word size is often chosen to be the size of a native pointer on the host platform
http://www.javaworld.com/javaworld/javaqa/2003-12/02-qa-1226-sizeof.html?page=1
Yes, a Java int is 32 bits in all JVMs and on all platforms, but this is only a language specification requirement for the programmer-perceivable width of this data type. Such an int is essentially an abstract data type and can be backed up by, say, a 64-bit physical memory word on a 64-bit machine.
So, will it be correct to conclude that the size of an int will be 32 bit in terms of the range of numbers which can be stored in an int variable but on a 64 bit machine this int variable could consume 64 bits of space?
Thanks,
Alok