Top 3 Null handling Interview Questions
Browse 3 real-world technical and behavioral interview questions about Null handling. Review scenarios, edge cases, and architectural best practices.
Your Collectors.toMap call passed every test and threw in production. What did the code assume, and what are your options?
It assumed unique keys and non-null values. Collectors.toMap throws IllegalStateException on a duplicate key and NullPointerException on a null value, so supply a merge function that encodes a real rule, use groupingBy when duplicates are legitimate, or collect into a HashMap directly if nulls must survive.
Adding a second LEFT JOIN doubled the revenue figure on a report. Explain what happened and write the correct query.
SQL join duplicates cause double counting when two one-to-many joins multiply rows before aggregation. Aggregate each child table to one row per parent first, then join those results back to the parent. Use this sql queries answer to show the decision, trade-off, and evidence rather than a memorised definition.
Write a query returning the second-highest salary in each department, then tell me what it does when two people tie for the top.
To get the second highest salary per department in SQL, rank employees inside each department with DENSE_RANK and filter rank two. DENSE_RANK handles ties where ROW_NUMBER or a global MAX gives the wrong result. Use this window functions answer to show the decision, trade-off, and evidence rather than a memorised definition. It also connects sql queries to the point an interviewer is testing.