Java Interview Questions
Practice with real Java interview questions
01
A Software Engineer was asked
Asked in 2026
Q. What is the Singleton design pattern in Java and how does it differ from the Factory design pattern?
Ans. The Singleton design pattern ensures that a class has only one instance and provides a global point of access to it. This is typically implemented by making the constructor private and providing a static method that returns the instance. Here's a simple implementation:
On the other hand, the Factory design pattern is used to create objects without specifying the exact class of object that will be created. It defines an interface for creating an object but allows subclasses to alter the type of objects that will be created. Here’s an example:
The key difference is that Singleton restricts instantiation to one object, while Factory provides a way to create different objects based on input parameters.
Software EngineerCore Concept
02
A Software Engineer was asked
Asked in 2025
Q. What is the difference between checked and unchecked exceptions in Java? Provide code examples to illustrate your answer.
Ans. In Java, exceptions are divided into checked and unchecked exceptions.
1. Checked Exceptions: These are exceptions that must be either caught or declared in the method signature using the
throws keyword. They are checked at compile-time.
2. Unchecked Exceptions: These exceptions do not need to be declared or caught. They occur during the runtime and are subclasses of RuntimeException.
In summary, the key difference lies in the way they are handled: checked exceptions must be handled explicitly, while unchecked exceptions do not require any explicit handling.Software EngineerCore Concept
