This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
1)a collection of 100 objects, each object has 10 attributes defined in POJO class and each attribute is set to have an Integer type with dummy value of 30.
2) a collection of 100 objects, each object has 1 attribute defined in POJO class and this attribute has an Integer value of 30.
Can I say the first collection approximately occupies 10 times memory than the second collection ? Can I simply calculate it this way ?
That is a reasonable way of estimating the memory use of objects, yes.
Suppose that the overhead for one of your POJO objects is P bytes, and the size of an Integer object is Q bytes. Then the total size of one of your POJOs will be P + Q bytes. If you now have 10 Integer objects instead of one Integer object in your POJO, the size will become P + 10 * Q bytes.
So 100 POJOs in the first case will be 100 * (P + Q) bytes, and 100 POJOs in the second case will be 100 * (P + 10 * Q) bytes.
If P is small compared to Q, then in the second case it will take approximately 10 times as much memory.
It's not easy to find out the exact size of objects in Java, or what the overhead per object (P) is, because it depends on the Java implementation (it might be different with different versions of Java, on different operating systems, or when using Java implementations from different vendors).
It might also be the case that you have thousands of different Integer(30) objects, or just one of them which everything refers to (in this simple example). This could make a difference, but what you said in your original post was approximately correct. For some value of "approximately".