Skip to content

Java Interview Question

 

Topic: Common

 

Junior Level (0–2 years)

 

🔹 Core Java

  • What are the differences between == and .equals()?
  • What are HashMap and Hashtable? Differences?
  • Explain the concept of OOP: Encapsulation, Inheritance, Polymorphism, Abstraction.
  • What is a final variable/class/method?
  • What is the difference between ArrayList and LinkedList?
  • What is method overloading vs method overriding?
  • Explain basic access modifiers: public, private, protected, default.

🔹 Exception Handling

  • Difference between checked and unchecked exceptions?
  • How does try-catch-finally work?

🔹 Java Basics

  • What is the purpose of static?
  • What are constructors? Can a constructor be private?
  • Explain the lifecycle of a Java object.

🔹 String & Collections

  • Why are Strings immutable?
  • How does HashMap work internally?
  • What is the difference between List, Set, and Map?
  • When do you use ArrayList vs LinkedList?

Mid-Level (2–5 years)

 

🔹 Java Features

  • What are Streams and how do you use them?
  • How does Optional help avoid NullPointerException?
  • What is the difference between synchronized and Lock?
  • Explain Functional Interfaces and Lambdas.

🔹 Multithreading

  • How does ExecutorService work?
  • What’s the difference between wait() and sleep()?
  • What is volatile? How does it work?
  • What is the difference between Runnable and Thread?

🔹 Design & Best Practices

  • What is SOLID principle?
  • How do you implement Singleton correctly?
  • Explain Dependency Injection.

🔹 JVM Knowledge

  • What are the memory areas in JVM?
  • Explain Garbage Collection phases.
  • What is the difference between stack and heap memory?

🔹 Spring Framework (if applicable)

  • Difference between @Component, @Service, and @Repository.
  • What is the Spring Bean lifecycle?
  • What is @Transactional used for?

Senior Level (5+ years)

 

🔹 Advanced Java

  • How does the Java memory model work?
  • Explain CompletableFuture and non-blocking programming.
  • Explain ClassLoaders and custom ClassLoader use cases.
  • How do you handle performance tuning for a high-load Java application?

🔹 Architecture & Design

  • How do you design a microservice architecture in Java?
  • What is Circuit Breaker pattern?
  • How do you ensure thread safety in concurrent applications?
  • Explain CAP theorem and how it applies in Java-based distributed systems.

🔹 Framework Mastery

  • Deep dive: How does Spring Boot autoconfiguration work?
  • Explain how AOP (Aspect-Oriented Programming) works in Spring.
  • How would you create a custom annotation in Java?

🔹 System Design / Integration

  • How do you handle retries, idempotency, and timeouts in external API calls?
  • What’s the difference between REST and gRPC? When to use each?
  • How do you design a scalable Java-based backend system?

 

 

Topic: Collections

 

Beginner level

What is the difference between List, Set, and Map?

Answer

1. List

  • Ordered collection of elements
  • Duplicates allowed
  • Access by index (like array)
  • Examples: ArrayListLinkedList

Use when:

  • You care about order
  • You might have duplicate values
  • You need to access items by position

2. Set

  • Unordered collection (some types may preserve order like LinkedHashSet)
  • No duplicates allowed
  • Each element must be unique
  • Examples: HashSetTreeSetLinkedHashSet

Use when:

Order is not important (unless using specific Set types)

You need to avoid duplicates

3. Map

  • Key-value pairs
  • Keys are unique, values can be duplicated
  • No index-based access
  • Examples: HashMapTreeMapLinkedHashMap

Use when:

  • You want to map a key to a value
  • You want to look up by key

What is the difference between ArrayList and LinkedList?

Answer

 

What are the key differences between HashSet and TreeSet?

What is the difference between HashMap and Hashtable?

How does HashMap work internally and what is load factor in HashMap?

Intermediate-level

What is the difference between Comparable and Comparator?

What is the difference between Iterator and ListIterator?

What is the difference between Fail-fast and fail-safe?

What are ConcurrentHashMap and how is it different from Collections.synchronizedMap()?

How does sorting work in collections? (e.g., Collections.sort())
What is the use of Queue and Deque interfaces?

Advance level

How does CopyOnWriteArrayList work and when should it be used?

What are the pros and cons of HashMap vs ConcurrentHashMap?

What is the role of equals() and hashCode() in collections?

What are the internal implementations of LinkedList, HashSet, and TreeMap?

What happens when two keys have the same hashcode in a HashMap?

 

 

Published inInterview

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *