32 bits. It's one of the Java language features that the size of the integer does not vary with the underlying computer. See the relevant section of the spec.

Answer from Thomas Jones-Low on Stack Overflow
🌐
Oracle
docs.oracle.com › javase › tutorial › java › nutsandbolts › datatypes.html
Primitive Data Types (The Java™ Tutorials > Learning the Java Language > Language Basics)
A primitive type is predefined by the language and is named by a reserved keyword. Primitive values do not share state with other primitive values. The eight primitive data types supported by the Java programming language are: byte: The byte data type is an 8-bit signed two's complement integer.
🌐
IBM
ibm.com › docs › en › i › 7.4.0
COBOL and Java Data Types
We cannot provide a description for this page right now
Discussions

On a 64-bit machine is the size of an int in Java 32 bits or 64 bits? - Stack Overflow
Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... 32 bits. It's one of the Java language features that the size of the integer does not vary with the underlying computer. More on stackoverflow.com
🌐 stackoverflow.com
How do I create a user defined array size? - Post.Byes
I'm trying to create a program that prompts the user for a number N. This number will be used to prompt the user N times to provide an integer. More on post.bytes.com
🌐 post.bytes.com
size of int in java
Hi, 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... More on forums.oracle.com
🌐 forums.oracle.com
June 22, 2009
Why the size of Java <int> data type has always been fixed versus to, for instance, the <int> size in C or C++?
Alexandra F is having issues with: There's a number of compiled languages, like C or C++; they are compiled to the machine code. Over time the size of integer in compiled code has... More on teamtreehouse.com
🌐 teamtreehouse.com
2
May 27, 2016
🌐
LabEx
labex.io › tutorials › java-how-to-calculate-java-array-size-runtime-418024
How to calculate Java array size runtime | LabEx
Learn efficient techniques to determine Java array size at runtime, explore length property, and master dynamic size calculation methods for optimal programming performance.
🌐
Great Learning
mygreatlearning.com › blog › it/software development › how to find array length in java
How to find Array Length in Java
September 12, 2024 - When we declare an array, the total number of elements in it is called the array's length, or we can also call it the size of the array. You can also take up a java programming free online course and learn more about the concepts before learning about arrays in java. Let us see the below example for a better understanding: int len = thisArray.length; Let us see a program using the Array Length attribute of Java: import java.util.*; class Main { public static void main(String[] args) { Integer[] intArray = {1,3,5,7}; //integer array String[] strArray = { "one", "two", "three", “four” }; //s
🌐
W3Schools
w3schools.com › java › java_data_types.asp
Java Data Types
assert abstract boolean break byte case catch char class continue default do double else enum exports extends final finally float for if implements import instanceof int interface long module native new package private protected public return requires short static super switch synchronized this throw throws transient try var void volatile while Java String Methods
Find elsewhere
🌐
Medium
medium.com › @AlexanderObregon › https-alexanderobregon-substack-com-p-subset-generation-with-bit-enumeration-c9e3f5182460
Subset Generation With Bit Enumeration In Java | Medium
2 weeks ago - An int in Java holds 32 bits. When totalMasks is computed as 1 << n, keeping n between 0 and 30 keeps totalMasks within the positive range and avoids overflow. long values hold 64 bits, so that bound moves up into the low sixties when masks are counted with 1L << n. Past that size, other ...
🌐
Post.Byes
post.bytes.com › home › forum › topic › java
How do I create a user defined array size? - Post.Byes
Scanner sc = new Scanner(); System.out.println("Enter size of your array"); int n = sc.nextInt(); int a[] = new int[n]; System.out.println("Enter values); for(int i = 0; i < a.length; i++) { a[i] = nextInt(); } ... import java.util.Arrays; import java.util.Scanner; public class PopulatingAnArray { public static void main(String args[]) { System.out.println("Enter the required size of the array :: "); Scanner s = new Scanner(System.in); int size = s.nextInt(); int myArray[] = new int [size]; System.out.println("Enter the elements of the array one by one "); for(int i = 0; i<size; i++) { myArray[i] = s.nextInt(); } System.out.println("Contents of the array are: "+Arrays.toString(myArray)); } }
🌐
GeeksforGeeks
geeksforgeeks.org › java › java-data-types
Java Data Types - GeeksforGeeks
They are broadly divided into two categories: Primitive Data Types: Store simple values directly in memory. Non-Primitive (Reference) Data Types: Store memory references to objects. ... Primitive data types store simple values directly in memory. Java provides eight primitive data types, each with a fixed size ...
Published   January 16, 2026
🌐
freeCodeCamp
freecodecamp.org › news › data-types-in-java
Data Types in Java
January 26, 2020 - Java defines 8 primitive data types : byte, short, int, long, char, float, double and boolean.
🌐
Codementor
codementor.io › community › primitive data types in java: understand the core essentials
Primitive Data Types In Java: Understand The Core Essentials | Codementor
March 22, 2024 - Add the Suffix "l" or "L" to an integer literal to turn it into a long. long myLong = 2147483648L; long myOtherLong = 2147483649l; For handling decimal numbers, Java offers two primitive data types: float and double.
🌐
Montana
cs.montana.edu › users › grayd › csci111 › lectures › mar9 › Arrays.pdf pdf
Arrays in Java CSCI 111
int[] x = Java Code · What Happens? Computer · Memory · int x; Java Code · What Happens? A new variable, x, is created. x can ONLY · hold an integer (variable declaration). x · Computer · Memory · int x; x = 5; Java Code · What Happens? A new variable, x, is created.
🌐
Quora
quora.com › Q1-What-is-the-size-of-the-int-data-type-in-Java
Q1.What is the size of the int data type in Java? - Quora
Answer (1 of 7): The size of the int data type in java is 4. In java,it is a type of Integral data type. int data type has wide range of uses. The range of int data type in java is -2,147,483,648 to 2,147,483,648. The int data type in java is, ...
🌐
Oracle
forums.oracle.com › ords › apexds › post › size-of-int-in-java-8930
size of int in java
June 22, 2009 - Hi, 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...
🌐
Oreate AI
oreateai.com › blog › understanding-array-size-in-java-a-comprehensive-guide › edc0c22dbe84fdf66968c3d7856cc6ff
Understanding Array Size in Java: A Comprehensive Guide - Oreate AI Blog
January 8, 2026 - Another key point about Java arrays is their theoretical maximum size—2,147,483,647 elements—which stems from using a signed 32-bit integer for indexing.
🌐
Quora
quora.com › What-is-the-size-of-int-in-a-Java-programming-language
What is the size of int in a Java programming language? - Quora
Answer (1 of 3): An integer datatype (int) occupies 4 bytes in JAVA. Whether you are using a 32 bit system or a 64 bit system the size of integer data type is fixed i.e; it is 4 bytes.
🌐
Reddit
reddit.com › r/javahelp › int array memory size
r/javahelp on Reddit: int array memory size
March 9, 2017 -

How many bytes does an int[] vs. Integer[] be in memory? Like including the overhead and extra data required, not just the data itself? I know it has an additional length which is an int (8 bytes).

Top answer
1 of 3
4

A primitive int obviously takes 4 byte.

An Integer object has an overhead of about 24 byte (this is implementation specific) plus 4 byte for the data, so about 28 byte.

An array is an object which also has an overhead of 24 bytes plus 4 bytes for the length plus data.

An int[] array thus uses 28 bytes plus 4 bytes for each int.

An Integer[] array uses 28 bytes plus 4-8 bytes to reference each Integer object plus 28 byte for each unique Integer object. In the worst case with uncached and unique Integer objects, this equals to 28 bytes array overhead plus 36 bytes for each value.

2 of 3
2

There are two things you have to take into account here:

  1. Overhead for the data itself (int vs. Integer)

  2. Overhead for the object reference

So, let's start :)

  1. Integer vs. int.

Primitive int is just a 4 bytes value (not 8 bytes as you've written). Integer is an object, which consists of a primitive int value (4 bytes) and object header. Object header can be 8, 12, or 16 bytes depending on the bitness of your JVM and UseCompressedOops flag. Here is Stackoverflow answer that describes the structure of the object header: https://stackoverflow.com/questions/26357186/what-is-in-java-object-header

UseCompressedOops is a flag that makes JVM optimize most of the references on 64-bit JVM and make them take 32 bits instead of 64 bits. If set, it should also make object header take 12 bytes instead of 16 bytes. (To be honest, I didn't measure this).

Given that, the overhead for a bunch of integers will be

number_of_elements * object_header_overhead

, where object_header_overhead =

  • 8 bytes (on 32 bit JVM)

  • 12 bytes (on 64 bit JVM with UseCompressedOops = true)

  • 16 bytes (on 64 bit without compressed oops)

But that's not the end of the story.

2. Size of object reference

int is a primitive, in another words it's just 4 bytes of data, and that's it. Integer is an object, which means it should be referenced from some another place in your program. If it is not referenced from anywhere, it's lost (and soon will be eaten by the GC).

Now, if you have an array of ints, then each element of it is a 4 byte int value. If you have an array of Integers, each element of it will be not Integer, but a reference to Integer object.

The size of an object reference is also can be different on different JVMs:

- 32 bits on 32 bit JVM

- 64 bits on 64 bit JVM

- 32 bits on 64 bit JVM with UseCompressedOops

Now you can calculate total overhead for your specific case. Here are few examples:

  1. Say, you run the following code on 32 bit JVM:

i1 = new Integer[100];
i2 = new int[100];

These are just empty arrays. The memory taken by them will be exactly the same, because each element of each array will take 4 bytes (0 int is 4 bytes, and null is 32 bits on 32 bit JVM).

2. Now, say you have 64 bit JVM without compressed oops.

i1 = new Integer[100];
i2 = new int[100];

for (int i = 0; i < 100; i++) {
  i1[i] = i; // implicit boxing: new Integer(i);
  i2[i] = i;
}

Now the memory taken by a single element of Integer array will consist of:

  • 4 bytes int value

  • 16 bytes - object header

  • 8 bytes object reference,

while an element of int array will only take 4 bytes. In total you have (16 + 8) * 100 = 240 bytes.

3. Of course, you can have more complicated situations, for instance (let's say, we have 64 bit JVM again):

i1 = new Integer[100];
i2 = new int[100];

int primInt = 42;
Integer wrappedInt = new Integer(42);

for (int i = 0; i < 100; i++) {
  i1[i] = wrappedInt;
  i2[i] = primInt;
}

As you can see, now every element of Integer array references a single Integer object. So, the total memory overhead will consist of:

  • 100 * 4 bytes (4 bytes for primitive int vs. 8 bytes for object reference on 64 bit JVM)

  • 20 bytes (size of the single Integer object, consisting of 16 bytes for the header and 4 bytes for the int value).

And couple more things to add:

  1. I don't guarantee that the information about the size of object header is 100% correct. This is what I remember about it, so please verify it yourself if you need to.

  2. Things can get even more complicated, because Java tends to cache Integers and reuse them. So actual memory of your programs can be less than expected.

🌐
Python documentation
docs.python.org › 3 › library › stdtypes.html
Built-in Types — Python 3.14.3 documentation
1 week ago - where the optional sign may by either + or -, integer and fraction are strings of hexadecimal digits, and exponent is a decimal integer with an optional leading sign. Case is not significant, and there must be at least one hexadecimal digit in either the integer or the fraction. This syntax is similar to the syntax specified in section 6.4.4.2 of the C99 standard, and also to the syntax used in Java 1.5 onwards.
🌐
TheServerSide
theserverside.com › blog › Coffee-Talk-Java-News-Stories-and-Opinions › int-vs-Integer-java-difference-comparison-primitive-object-types
Integer vs. int: What's the difference?
The key difference between the Java int and Integer types is that an int simply represents a whole number, while an Integer has additional properties and methods.