Java Interview Detailed Notes (Up to Exception
Handling)
OOP & Inheritance
Inheritance allows a child class to acquire properties of a parent class. Method overriding requires
same name and parameters with optional covariant return type.
Static methods belong to class and are resolved at compile time (method hiding). Non-static
methods use runtime polymorphism.
Final keyword: final variable cannot be reassigned, final method cannot be overridden, final class
cannot be extended.
JVM & Memory
Java code is compiled into bytecode (.class). JVM executes bytecode.
Heap: stores objects. Stack: stores method calls and references.
Class loading is lazy (on demand), not all classes loaded at once.
Strings
Strings are immutable. Stored in String Constant Pool (SCP).
String s1 = "hello";
String s2 = "hello"; // same reference
new String() creates a new object in heap.
StringBuilder: mutable, fast, not thread-safe.
StringBuffer: mutable, thread-safe, slower.
equals() and hashCode()
equals() compares logical equality. hashCode() determines bucket location.
Contract: if equals() is true, hashCode() must be same.
Used in HashMap/HashSet for lookup.
Exception Handling
Exceptions disrupt normal flow. Types: Checked and Runtime.
try-catch-finally handles exceptions. finally always executes (except JVM termination).
throw is used to explicitly throw exception. throws declares exception.
finally with return overrides try return.