Interview Q&A / Java
Java interview questions
Collections, the JVM, strings, exceptions and threads, the backbone of most campus placement rounds.
Prefer rapid revision? Practise Java short interview answers →
- What is the difference between final, finally and finalize in Java?
final is a keyword that stops change (a variable cannot be reassigned, a method cannot be overridden, a class cannot be extended). finally is a block that runs after try/catch, usually for cleanup. finalize() was a method the garbage collector might call before removing an object; it is deprecated for removal and should not be used.
BeginnerIn-depth3 min read - Does calling System.gc() force garbage collection in Java?
No. System.gc() is only a hint, and the JVM may ignore it. Even when it runs, it often triggers an expensive full collection, so production code should not call it.
BeginnerQuick answer1 min read - When does an object become eligible for garbage collection in Java?
An object is eligible once no live thread can reach it through any chain of references from the GC roots, such as local variables, static fields and active threads. Setting a reference to null or leaving its scope can make it unreachable.
BeginnerQuick answer1 min read