Q1. What is the difference between == and .equals() in Java?
== compares object references — it checks whether two variables point to the exact same object in memory. .equals() compares the content or value of two objects as defined by the class's equals() method. For String, Integer, and most value objects always use .equals(). String literals may pass == due to the string pool, which creates a false sense of correctness. When you override equals() you must also override hashCode() so objects work correctly in HashMap and HashSet. This is one of the most common Java interview questions.