Reputation: 511
I was going through the book "Java-The Complete Reference" and I came across a sentence which says that
"The width of an integer type should not be thought of as the amount of storage it consumes,but rather as the behavior it defines for variables and expressions of that type. The java run-time environment is free to use whatever size it wants,as long as the types behave as you declared them".
Does this mean the java is free to choose the size of the integer data type which is typically of 4 bytes?
Upvotes: 6
Views: 219
Reputation: 823
"The width of an integer type should not be thought of as the amount of storage it consumes,
A JVM may store a Java 16-bit short
in 32 bits on 32-bit implementations to improve performance...
but rather as the behavior it defines for variables and expressions of that type.
... but it will behave like a 16-bit signed two's complement integer, regardless of how it's stored in memory.
The java run-time environment is free to use whatever size it wants,as long as the types behave as you declared them".
If a program needs to run on any JVM, all JVMs need to treat the program and its integers in the same way. But how the JVM is implemented doesn't matter to a Java developer, which allows for optimizations that are specific to the architecture.
Upvotes: 8