Strings and Exception Handling Interview Questions for Java
25 Strings and Exception Handling questions with answers for java roles — 11 easy, 12 medium, 2 hard.
About Strings and Exception Handling
Strings appear in almost every coding round, and exception handling in every design discussion. Learn string immutability, the string pool, StringBuilder, text blocks and classic string problems, then checked and unchecked exceptions, try-with-resources, custom exceptions, chaining and how to design clean error handling for REST APIs.
What is the String constant pool?
Show answer
Compare String, StringBuilder and StringBuffer.
Show answer
What is the difference between checked and unchecked exceptions?
Show answer
What is try-with-resources?
Show answer
What is the difference between throw and throws?
Show answer
What are text blocks in Java?
Show answer
Write a Java method to check whether a string is a palindrome, ignoring case and non-letters.
Show answer
Count the frequency of each character in a string using Java.
Show answer
Write code to check if two strings are anagrams.
Show answer
How do you handle disagreement with a reviewer about your code?
Show answer
Does the finally block always execute?
Show answer
How do you create a custom exception and when should you?
Show answer
What is exception chaining?
Show answer
Is it good practice to catch Exception or Throwable?
Show answer
A log file shows a NullPointerException only for some users. How do you debug it?
Show answer
Code builds a large CSV report with String += inside a loop and it is very slow. Why and what is the fix?
Show answer
Exceptions are being swallowed with empty catch blocks in your codebase. How would you fix this?
Show answer
Your REST API returns stack traces to clients when errors happen. How do you design proper error handling?
Show answer
Write a custom unchecked exception and a Spring handler that returns HTTP 404.
Show answer
Find the first non-repeating character in a string.
Show answer
Read a large text file line by line efficiently and count lines containing ERROR.
Show answer
Tell me about a time a production incident happened because of your code.
Show answer
A file handle leak causes Too many open files errors after a day. What is the likely cause?
Show answer
Should a service layer throw checked or unchecked exceptions? Defend your choice.
Show answer
Frequently asked questions
How important is Strings and Exception Handling in Java interviews?
Strings appear in almost every coding round, and exception handling in every design discussion. Learn string immutability, the string pool, StringBuilder, text blocks and classic string problems, then checked and unchecked exceptions, try-with-resources, custom exceptions, chaining and how to design clean error handling for REST APIs.
How should I use the Strings and Exception Handling sheet?
Go top to bottom — easy to hard. Answer before opening each answer, tick what you solved and save misses to Last-Minute Revision.