Q:

Java - Memory allocation for int value 1 vs 2,147,483,647

Java allocates 4 bytes of memory to an integer. But does this happen for all the int value no matter what the value is ? 
For example 0 or 1 can represented by a bit against a larger value like 2,147,483,647 which could need 2^31-1 bits. 
When JVM allocates memory for an integer does it blindly allot 4 bytes for every single int var or does it allocate more memory as the number gets bigger?

A:

An int variable will always take 4 bytes. It would be a waste of time trying to optimize the space used depending on the actual value. The programmer is responsible for making the decision how many bytes he needs for a variable.

