• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

JVM & Garbage Collections

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In one of my interview, I had faced with below two questions. Though I had explained it, I think interviewer is not satisfied with it. For these two questions what are the important points to be conveyed?

Explain working of Java Virtual Machine (JVM)
Garbage collection mechanism in Java

[ September 15, 2005: Message edited by: Sachin Ramesh Vir ]
 
High Plains Drifter
Posts: 7289
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to Jobs Discussion
 
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Explain working of Java Virtual Machine (JVM)



Executes byte code that is compiled with Javac. Bytecode can be reversed back JVM is implemented for all major systems, that's why Java is cross-platform - byte code is OS independant.

Garbage collection mechanism in Java



When there is no reference pointing to object, the object can be removed by GC. Though you can't tell the precise time when it be removed. GC usually runs in it's own thread and cleans memory periodically or when system is low on physical memory. You can ask GC to do system clean up right now - System.gc(). There is finalize method in every object. You can override it so it will get control when GC will determine the object will be deleted and before it is actually deleted.

Would I pass?
 
Vladas Razas
Ranch Hand
Posts: 385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Two important things about Java's memory:

1) Yes, Java programs can leak memory. That happens when program stores references it does no longer need. That might happen with event listeners and observer (etc). If you register your object as listener but then don't use it anymore it will not be deleted as event source will still try to notify that object and keep reference. Unless event source is also de-referenced. Or the object is removed from listeners list.

2) Circular references are also detected and deleted by GC. If your A references B, but nobody else references neither A nor B then both will get deleted.
reply
    Bookmark Topic Watch Topic
  • New Topic