Do you know how much memory the string has? I have heard all kinds of answers to this question, ranging from "do not know" to "string has 2 bytes". Here are some more questions: How much space does empty string take? How much space does the class object of Integer take? How much space will take your own class object with three Integer fields? It is funny, but none of my Java programmer friends could answer these questions ... Most of us do not need it, and nobody will think about it in the real java projects. After all, this is the same as you would not know the engine capacity of vehicle that you drive every day. You can be a great driver and did not even know what 2.4 or 1.6 means on your car. But I am sure that there are few people who are not familiar with the meaning of these numbers. So why do java programmers know so little about this part of their tool?
Integer vs int
We all know that in java - everything is an object. Except, perhaps, primitives and references to the objects themselves. Let us consider two typical situations: