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.
Win a copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java this week in the Agile and Other Processes forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

How memory is allocated to objects in heap?

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi..
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???
 
Marshal
Posts: 68057
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

And welcome to the Ranch
 
Archana Thule
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks 4 reply
 
Sheriff
Posts: 21865
105
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please UseRealWords: "for", not "4".
 
Who knew that furniture could be so violent? Put this tiny ad out there to see what happens:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!