Core Java Interview Questions & Answers (Cheat
Sheet)
Q: What are the main features of Java?
■ Object-oriented, platform independent, simple, secure, robust, multithreaded, distributed,
automatic GC.
Q: Difference between JDK, JRE, and JVM?
■ JDK: Development kit (JRE+compiler). JRE: Runtime env (libs+JVM). JVM: Executes bytecode.
Q: What is bytecode?
■ Intermediate code generated after compilation, executed by JVM.
Q: Abstraction vs Encapsulation?
■ Abstraction: Hiding implementation (abstract class/interface). Encapsulation: Wrapping
data+methods (class, modifiers).
Q: Interface vs Abstract class?
■ Interface: Only abstract (Java8+ default/static). Supports multiple inheritance. Abstract:
abstract+concrete methods.
Q: Overloading vs Overriding?
■ Overloading: Same method, diff params (compile-time). Overriding: Subclass redefines (runtime).
Q: final vs finally vs finalize()?
■ final: constant/no override/inheritance. finally: always executes in try/catch. finalize(): called by
GC before destroy.
Q: == vs equals()?
■ ==: reference compare. equals(): value compare.
Q: String vs StringBuilder vs StringBuffer?
■ String: Immutable. StringBuilder: Mutable, faster, not thread-safe. StringBuffer: Mutable,
thread-safe, slower.
Q: List vs Set vs Map?
■ List: ordered, duplicates. Set: unordered, no duplicates. Map: key-value, unique keys.
Q: HashMap vs Hashtable?
■ HashMap: not sync, allows null, faster. Hashtable: sync, no nulls, slower.
Q: Comparable vs Comparator?
■ Comparable: natural ordering (compareTo). Comparator: custom ordering (compare).
Q: Process vs Thread?
■ Process: independent, own memory. Thread: lightweight, shares memory.
Q: sleep() vs wait()?
■ sleep(): pause, doesn’t release lock. wait(): pause until notify, releases lock.
Q: Checked vs Unchecked exceptions?
■ Checked: compile-time (IOException). Unchecked: runtime (NPE, ArithmeticEx).
Q: throw vs throws?
■ throw: used to explicitly throw exception. throws: declares exceptions a method may throw.
Q: What are lambda expressions?
■ Anonymous function: (args) -> expression.
Q: Functional interface?
■ Interface with 1 abstract method (@FunctionalInterface). E.g., Runnable.
Q: map() vs flatMap()?
■ map(): transforms element. flatMap(): flattens + transforms stream.
Q: Optional class?
■ Represents value that may/may not exist. Prevents NullPointerException.