Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

java int size fixed or variable?

Tags:

java

Is integer size in java of fixed length or variable size?

ex: 1 or 10000 does both the number takes same space during allocation?

like image 335
realnumber Avatar asked Feb 19 '11 02:02

realnumber


2 Answers

Java integers are 32 bits (4 octets) as per the JLS.

The integral types are byte, short, int, and long, whose values are 8-bit, 16-bit, 32-bit and 64-bit signed two's-complement integers, respectively.

Source: JLS §4.2 Primitive Types and Values

like image 118
Matt Ball Avatar answered Oct 24 '22 04:10

Matt Ball


It's fixed in size. All ints in Java are 32 bits, both from the programmer's perspective and the machine's.

The Java VM specification, which describes the JVM bytecode format, mentions that each int is 32 bits. (Aside: boolean values can take up any number of bits, as can objects.)

like image 7
ide Avatar answered Oct 24 '22 04:10

ide