💻Technical15 min

Java Interview Questions & Answers

Java remains one of the most dominant languages in enterprise software, Android development, and backend systems. Java interviews are thorough and multi-layered — they test core language fundamentals, OOP principles, Collections Framework, Multithreading, JVM internals, and increasingly Spring Boot and microservices architecture.

Java Interview Topics by Experience Level

Know what to expect based on your experience:

  • 0–1 year: OOP concepts, Collections, basic I/O, exception handling
  • 1–3 years: Multithreading, JDBC, design patterns, Spring Core
  • 3–5 years: Spring Boot, Microservices, JVM tuning, advanced concurrency
  • 5+ years: System design, distributed systems, Java architecture decisions

Core Java Concepts You Must Know

These fundamentals are tested at every level:

  • OOP: inheritance, encapsulation, polymorphism, abstraction — with Java examples
  • Access modifiers: public, private, protected, default
  • static keyword: static methods, static blocks, static inner classes
  • Abstract class vs. interface — when to use which in Java 8+
  • String immutability and String pool
  • Exception handling: checked vs. unchecked, custom exceptions, finally block
  • Java 8 features: lambda expressions, Stream API, Optional, default interface methods
  • Java 17 features: records, sealed classes, text blocks, pattern matching

Collections Framework

Collections are heavily tested — know the internals, not just the usage:

  • List: ArrayList (dynamic array), LinkedList (doubly linked) — performance differences
  • Set: HashSet (no order), LinkedHashSet (insertion order), TreeSet (sorted)
  • Map: HashMap (O(1) average), LinkedHashMap (insertion order), TreeMap (sorted)
  • Queue: LinkedList, ArrayDeque, PriorityQueue
  • Why ArrayList is preferred over Vector
  • HashMap internal working: hashing, bucket collision, load factor, rehashing
  • Fail-fast vs. fail-safe iterators
  • ConcurrentHashMap vs. Collections.synchronizedMap()

Multithreading & Concurrency

One of the most complex and most tested areas for mid-senior Java roles:

  • Thread creation: extends Thread vs. implements Runnable vs. Callable/Future
  • Synchronisation: synchronized keyword, volatile, atomic variables
  • Java Memory Model: happens-before relationship
  • Executor framework: ThreadPoolExecutor, FixedThreadPool, CachedThreadPool
  • Locks: ReentrantLock, ReadWriteLock vs. synchronized blocks
  • Deadlock: causes, prevention, and detection
  • CompletableFuture for async programming in Java 8+

Spring Boot (For Backend Roles)

Spring Boot is the most commonly used Java framework in enterprise environments:

  • IoC and Dependency Injection — how Spring manages beans
  • Annotations: @Component, @Service, @Repository, @Controller, @RestController
  • @Autowired, @Qualifier, @Bean — bean injection
  • Spring MVC request flow: DispatcherServlet → Controller → Service → Repository
  • Spring Data JPA: CrudRepository, JpaRepository, custom @Query
  • Spring Security: authentication, authorisation, JWT integration
  • Spring Boot Actuator for monitoring and health checks

Common Interview Questions & Answers

Q1. What is the difference between == and .equals() in Java?

== compares object references (memory addresses). .equals() compares object content. For String comparisons, always use .equals(). Two String objects with the same value using 'new String()' will be == false but .equals() true.

Always give a concrete String example — it makes the concept tangible.

Q2. How does HashMap work internally?

HashMap uses an array of buckets. When you put a key-value pair, it computes hashCode() of the key, applies a hash function to find the bucket index, and stores the entry. If two keys have the same bucket (hash collision), entries are stored as a linked list (Java 8+ converts to a balanced tree when >8 entries). Load factor (default 0.75) triggers rehashing when the map is 75% full.

Demonstrate knowledge of Java 8's treeification of buckets — it signals depth.

Q3. What is the difference between an abstract class and an interface in Java 8+?

Abstract class: can have state (instance variables), constructors, and implemented methods. A class can only extend one abstract class. Interface: can now have default and static methods (Java 8+). A class can implement multiple interfaces. Use abstract class when sharing code among closely related classes; use interface to define a contract for unrelated classes.

Mention the Java 8 changes to interfaces — this shows you are up to date.

Common Mistakes to Avoid

Using == for String comparison instead of .equals()

Not knowing HashMap's internal working (very common question)

Confusing checked and unchecked exceptions

Not understanding the thread lifecycle and synchronisation

Ignoring Java 8+ features like streams and lambdas

Expert Tips

Code every concept you learn — don't just read it

Practice on HackerRank's Java track for coding challenges

Know 5 design patterns cold: Singleton, Factory, Observer, Strategy, Builder

Build one Spring Boot REST API project — interviewers love hands-on experience

Pre-Interview Checklist

6 items

Frequently Asked Questions

Is Java still relevant in 2026?

Absolutely. Java powers banking systems, enterprise ERP, Android, and large-scale backends at Amazon, Microsoft, LinkedIn, and Flipkart. It is the most in-demand backend language in India's enterprise and product company markets.

Should I learn Java 17 or Java 11 for interviews?

Learn Java 17 — it is the current LTS (Long-Term Support) release. Know the features: records, sealed classes, text blocks, and pattern matching for instanceof. Most companies have migrated from Java 8 to Java 11 or 17.

🎯

Ready to ace your next interview?

Practice with SpeakWell AI. Upload your resume → get resume-based questions → practice with AI interviewers → improve communication → track progress → get instant AI feedback.

Back to all guides