Java Interview Notes (Up to Exception Handling)
OOP Concepts
Inheritance allows child classes to extend parent behavior. Overriding requires same signature and
allows covariant return types.
Static methods belong to class (compile-time binding), non-static methods use runtime
polymorphism.
Final keyword: variables can't change, methods can't be overridden, classes can't be extended.
JVM and Memory
Java code is compiled into bytecode (.class) which JVM executes.
Heap stores objects, Stack stores references and method calls.
Class loading happens dynamically when needed.
Strings
Strings are immutable. String Constant Pool (SCP) avoids duplicates.
new String() creates object in heap; literals go to SCP.
StringBuilder is fast and non-thread-safe; StringBuffer is thread-safe but slower.
equals() and hashCode()
equals() compares values, hashCode() determines bucket location in hash structures.
If equals() is true, hashCode must be same.
Both must be overridden together for correct HashMap/HashSet behavior.
Exception Handling
Exceptions disrupt program flow. Checked exceptions are compile-time, runtime exceptions occur
during execution.
try-catch-finally is used for handling. finally always executes unless JVM exits.
throw is used to explicitly throw exceptions; throws declares them.
finally with return overrides try return.