Java – Interview Questions
Explore a curated collection of Java interview questions covering a wide range of topics and difficulty levels—from beginner to advanced. Whether you’re just starting out or preparing for senior-level interviews, this page helps you practice effectively with clear questions, concise answers, and in-depth explanations.
Use the filter to quickly find questions by level and focus on the areas that matter most to you. Each question is designed to reinforce key concepts, improve your problem-solving skills, and prepare you for real-world technical interviews.
Start practicing, test your knowledge, and get interview-ready with structured, high-quality Java questions.
Collections Framework
Advanced
What is the advantage of ConcurrentHashMap over HashMap?
ConcurrentHashMap allows concurrent read and write operations without full synchronization improving performance in multi-threaded environments.
Collections Framework
Advanced
How can you safely access collections concurrently in Java?
You can use synchronized wrappers like Collections.synchronizedList or concurrent collections like CopyOnWriteArrayList and ConcurrentHashMap which provide better scalability.
Interfaces and Abstractions
Beginner
What is a functional interface?
A functional interface has exactly one abstract method and can be used as the target for lambda expressions improving concise coding.
Interfaces and Abstractions
Intermediate
What are default methods in interfaces?
Default methods allow interfaces to provide method implementations. They were introduced to enable backward compatibility when adding new methods to existing interfaces.
Interfaces and Abstractions
Intermediate
Can an abstract class have constructors?
Yes abstract classes can have constructors which are called when a subclass is instantiated helping initialize inherited state.
Interfaces and Abstractions
Beginner
Why can’t abstract classes be instantiated?
Abstract classes are incomplete and may contain abstract methods without implementation so they cannot be instantiated directly and must be subclassed.
Interfaces and Abstractions
Advanced
When should you use an interface over an abstract class?
Use interfaces when defining capabilities that multiple unrelated classes can implement. Abstract classes are better when sharing common behavior and state.
Interfaces and Abstractions
Intermediate
What is the difference between abstract classes and interfaces?
Abstract classes can have state constructors and both abstract and concrete methods while interfaces define contracts and support default and static methods but no instance state.
Interfaces and Abstractions
Advanced
What is type erasure in Java generics?
Type erasure is the process where generic type information is removed at runtime. The compiler replaces type parameters with their bounds ensuring backward compatibility with older Java versions.
Interfaces and Abstractions
Intermediate
What problem do generics solve in Java?
Generics provide type safety at compile time by allowing classes and methods to operate on parameterized types. They eliminate the need for casting and reduce runtime errors such as ClassCastException.
Exception Handling
Beginner
What is the role of finally block?
The finally block is executed regardless of whether an exception occurs ensuring cleanup operations like closing resources.
Exception Handling
Beginner
How do exceptions affect program flow?
When an exception occurs normal execution stops and control is transferred to the nearest matching catch block. If not handled the program terminates.
Exception Handling
Intermediate
What is the difference between Exception and Error?
Exception represents conditions an application can handle while Error represents serious problems that should not be caught such as OutOfMemoryError.
Exception Handling
Intermediate
What is the hierarchy of exceptions in Java?
All exceptions inherit from Throwable which has two main branches Exception and Error. Exception includes checked and unchecked types while Error represents serious system issues.
Exception Handling
Intermediate
What is exception propagation?
Exception propagation is the process where an exception is passed up the call stack until it is handled or terminates the program.
Exception Handling
Beginner
What is the difference between throw and throws?
throw is used to explicitly throw an exception while throws declares exceptions that a method may produce.
Exception Handling
Intermediate
What are best practices for custom exceptions?
Extend appropriate base classes provide meaningful names include useful messages and avoid excessive hierarchy.
Exception Handling
Intermediate
Why should you create custom exceptions?
Custom exceptions provide meaningful error handling tailored to your application making debugging and maintenance easier.
Exception Handling
Intermediate
When should you use checked exceptions?
Use checked exceptions when the caller can reasonably recover from the error such as IO operations or external resource failures.
Exception Handling
Beginner
What is the difference between checked and unchecked exceptions?
Checked exceptions are verified at compile time and must be handled or declared while unchecked exceptions occur at runtime and are not enforced by the compiler.