SarthiQ

SarthiQ

Interview Preparation Guide

Java
Questions & Answers

A comprehensive, expert-curated list of real interview questions to help you prepare effectively and land your dream job.

Document Details

Topic / Subject
Java
Content Length
15 Curated Q&A
Generated On
October 4, 2026
Provided By
SarthiQ.com
Want to explore more questions & mock interviews? Click on 👉www.sarthiq.com
© 2026 SarthiQ Platform. All rights reserved.
www.sarthiq.com
Resume Upload Get Job in 90 Days Resume Builder AI Interview Coach Interview Questions Placement Committee Self Assessment Get Internship

Need Help?

[email protected]

Top Java Interview Questions

NETFLIX
ORACLE
Adobe
NVIDIA
meta
IBM
wipro
TCS
cisco
intel
SAP
Uber

Java Interview Questions

Practice with real Java interview questions

01
A Software Engineer was asked
SarthiQ Java
Medium
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:
java
public class Singleton {
    private static Singleton instance;

    private Singleton() {} // Private constructor

    public static Singleton getInstance() {
        if (instance == null) {
            instance = new Singleton();
        }
        return instance;
    }
}
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:
java
interface Shape {
    void draw();
}

class Circle implements Shape {
    public void draw() { System.out.println("Drawing Circle"); }
}

class Square implements Shape {
    public void draw() { System.out.println("Drawing Square"); }
}

class ShapeFactory {
    public static Shape getShape(String shapeType) {
        if (shapeType.equalsIgnoreCase("CIRCLE")) {
            return new Circle();
        } else if (shapeType.equalsIgnoreCase("SQUARE")) {
            return new Square();
        }
        return null;
    }
}
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
SarthiQ Java
Medium
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.
java
import java.io.File;
   import java.io.FileReader;
   import java.io.IOException;

   public class CheckedExceptionExample {
       public void readFile(String filePath) throws IOException {
           File file = new File(filePath);
           FileReader fr = new FileReader(file);
           fr.read();
           fr.close();
       }
   }
2. Unchecked Exceptions: These exceptions do not need to be declared or caught. They occur during the runtime and are subclasses of RuntimeException.
java
public class UncheckedExceptionExample {
       public void divide(int a, int b) {
           int result = a / b; // This may throw ArithmeticException if b is 0
           System.out.println("Result: " + result);
       }
   }
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
03
Software Engineer
SarthiQ Java
Hard

Question:

How would you design a scalable system for XYZ...

04
Software Engineer
SarthiQ Java
Hard

Question:

How would you design a scalable system for XYZ...