2

Could someone explain this text from Herbert Schildt.

"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."

1
  • 2
    Downvoters: please give the new guy some explanation as to why you think this is a bad question. I think it is an entirely reasonably thing to ask. Commented May 25, 2016 at 12:30

1 Answer 1

8

It is saying is that an int isn't necessarily implemented a 32-bit block of memory; it might be implemented, for example, as a 64-bit block of memory.

You don't really need to care about this, from the perspective of your code's behaviour: all you need know is that it behaves like a 32-bit block of memory, e.g. it can only store values between -2^31 and 2^31 - 1.

You might need to care about it if you are storing lots of ints: if it is storing them in 64 bits of memory each, you need twice as much memory as if they were stored in 32 bits. But this doesn't change the correctness of the code itself.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.