Model answers for 4 core Java questions
Typical round: 30-45 minutes, 10-15 questions plus one coding task
Q: Why is String immutable in Java? A: Immutability lets Strings be safely shared from the string pool, cached for hash codes, and used as HashMap keys and in security-sensitive places like class loading and file paths. Any change creates a new String; use StringBuilder for repeated modification.
Q: How does HashMap work internally? A: It stores entries in an array of buckets. The key's hashCode picks a bucket, and equals resolves collisions within it. Since Java 8, a bucket with many entries turns from a linked list into a balanced tree. When size passes capacity times load factor (0.75 by default), the table resizes.
Q: What is the difference between checked and unchecked exceptions? A: Checked exceptions, like IOException, must be handled or declared at compile time. Unchecked exceptions extend RuntimeException, like NullPointerException, and usually signal programming errors that should be fixed, not caught.
Q: What is the difference between == and equals()? A: == compares references for objects, while equals() compares logical content when a class overrides it, as String does. If you override equals, also override hashCode so hash-based collections work correctly.