lostsoul29
lostsoul29

Reputation: 756

Java size of Long and String objects

Here, the author's tests say that Integer and Long objects occupy the same amount of memory, i.e., 16 bytes. However, when I run the exact code in an online Java compiler here, I get different results. A Long object seems to occupy 24 bytes.

Furthermore, the author says an empty String object occupies 40 bytes memory. However, the online compiler says it occupies 24 bytes.

Why could this be happening? Has there been an update to the Java compiler?

Note: The author does note that their results are based on Sun's JDK 1.3.1 for Windows and warns that they may change.

Upvotes: 0

Views: 1104

Answers (1)

吳俊霆
吳俊霆

Reputation: 74

The author clearly states:

Note: The following results are based on Sun's JDK 1.3.1 for Windows. Due to what is and is not guaranteed by the Java language and JVM specifications, you cannot apply these specific results to other platforms or other Java implementations.

Upvotes: 4

Related Questions