This week's book giveaway is in the Agile and Other Processes forum. We're giving away four copies of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java and have Dr. Raoul-Gabriel Urma & Richard Warburton on-line! See this thread for details.
This is the question i was asked in a recent interview...
Suppose the heap is of size 25k in which 3 objects of 5k each have been allocated memory. 2 object are in consecutive memory locations then there is gap of 5k and then third object is located.
| 3rd obj |
| 2nd obj |
| 1st obj |
Now the question was how jvm will allocate memory to an object of 10k???
I was not sure on this... but i could think of 2 ways... either 3rd object will be moved down or dat 10k objects will get memory in 2 chunks of 5k each...
what is the right answer???
The correct answer is that it varies from implementation to implementation. The correct way to answer an interview question is to say it depends on how things are stored, and ask them for a little extra detail before you give them an answer. You probably did well to say there are several possibilities.