Java interviews for freshers and early-career developers are remarkably predictable. After sitting through debriefs with interview panels for years, we can tell you that most of the questions come from the same few areas: core Java, collections, Java 8 features, exceptions, a little multithreading, Spring Boot and SQL.
Below are the questions we see most often, with short answers in the way a good candidate would actually say them in an interview. Do not memorise word for word. Understand each answer well enough to explain it with your own example.
Core Java and OOP
1. What is the difference between JDK, JRE and JVM?
The JVM runs Java bytecode. The JRE is the JVM plus the libraries needed to run Java programs. The JDK is the JRE plus development tools such as the compiler (javac). To write and compile code you need the JDK.
2. What are the four pillars of OOP?
Encapsulation (keeping data private and exposing it through methods), Inheritance (a class reusing another class’s behaviour), Polymorphism (one interface, many forms: method overloading and overriding), and Abstraction (showing what an object does, hiding how). Give an example from your project, such as a Payment interface with CardPayment and UpiPayment classes.
3. What is the difference between == and equals()?
== compares references (whether two variables point to the same object) for objects, and values for primitives. equals() compares content, if the class overrides it, as String does. Two different String objects with the same text are equals() but not ==.
4. Why is String immutable in Java?
Once created, a String cannot change. This makes Strings safe to share (string pool), safe across threads, and reliable as HashMap keys because their hashCode does not change. Operations like concat create a new String.
5. String vs StringBuilder vs StringBuffer?
String is immutable. StringBuilder is mutable and faster for repeated changes but not thread-safe. StringBuffer is mutable and thread-safe (synchronised), so slightly slower. In a loop that builds text, use StringBuilder.
6. Difference between an abstract class and an interface?
An abstract class can have state (fields), constructors and both abstract and concrete methods; a class can extend only one. An interface defines a contract; since Java 8 it can have default and static methods, and a class can implement many interfaces. Use an interface for a capability ("can be paid"), an abstract class for a shared base with common code.
7. What is method overloading vs overriding?
Overloading: same method name, different parameters, in the same class, resolved at compile time. Overriding: a subclass provides its own version of a parent method with the same signature, resolved at runtime.
8. What do final, finally and finalize mean?
final makes a variable constant, a method non-overridable or a class non-inheritable. finally is a block that runs after try/catch, used for cleanup. finalize() was meant for cleanup before garbage collection but is deprecated; use try-with-resources instead.
9. What is the difference between static and instance members?
Static members belong to the class and are shared by all objects; instance members belong to each object. A static method cannot directly use instance variables.
Collections
10. ArrayList vs LinkedList?
ArrayList uses a dynamic array: fast random access by index, slower inserts in the middle. LinkedList uses nodes: faster inserts and removals at known positions, slow access by index. In practice ArrayList is the default choice for most cases.
11. How does HashMap work internally?
HashMap stores entries in an array of buckets. It calls hashCode() on the key to find a bucket, then uses equals() to find the exact key inside that bucket. Collisions are stored as a linked list, and since Java 8 a bucket with many entries is converted to a balanced tree for faster lookup. When the map grows past its load factor (0.75 by default), it resizes and rehashes.
12. Why must you override hashCode() when you override equals()?
Because equal objects must have the same hash code. If you override only equals(), two equal keys can land in different buckets and HashMap or HashSet will treat them as different.
13. HashMap vs ConcurrentHashMap vs Hashtable?
HashMap is not thread-safe and allows one null key. Hashtable is a legacy synchronised map that locks the whole table. ConcurrentHashMap is thread-safe with much better concurrency and is the modern choice for shared maps.
14. HashSet vs TreeSet?
HashSet has no order and is faster. TreeSet keeps elements sorted and is slower. Both do not allow duplicates.
15. Comparable vs Comparator?
Comparable defines the natural order inside the class (compareTo). Comparator defines an external order you can pass in, useful for sorting the same objects in different ways, for example employees by name or by joining date.
Exceptions
16. Checked vs unchecked exceptions?
Checked exceptions (like IOException) must be handled or declared at compile time. Unchecked exceptions (subclasses of RuntimeException, like NullPointerException) are not checked by the compiler and usually signal programming errors.
17. What is try-with-resources?
A try block that automatically closes resources such as files or database connections that implement AutoCloseable, even if an exception occurs. It replaces manual closing in finally.
18. How do you create a custom exception?
Extend Exception (checked) or RuntimeException (unchecked), add constructors, and throw it with a clear message, for example InsufficientBalanceException in a banking project.
Java 8 and modern Java
19. What are lambda expressions and functional interfaces?
A functional interface has exactly one abstract method (like Runnable or Comparator). A lambda is a short way to provide that method’s implementation, for example list.sort((a, b) -> a.getName().compareTo(b.getName())).
20. What is the Stream API? Give an example.
Streams process collections in a declarative way with operations like filter, map and collect. Example: employees.stream().filter(e -> e.getDept().equals("IT")).map(Employee::getName).collect(Collectors.toList()). Streams do not change the source collection.
21. map() vs flatMap()?
map transforms each element into one element. flatMap transforms each element into a stream and flattens them into one stream, useful for a list of lists.
22. What is Optional and why use it?
Optional is a container that may or may not hold a value. It makes "no value" explicit and reduces NullPointerExceptions, for example a repository method returning Optional<User>.
23. Which newer Java features do you know?
Mention what you have actually used: var for local variables, records for simple data classes, text blocks, switch expressions, and the fact that teams typically use long-term support (LTS) versions. Only claim what you can show.
Multithreading basics
24. Thread vs Runnable? How do you create threads in real projects?
You can extend Thread or implement Runnable (preferred, because Java allows only single inheritance). In real projects we usually use an ExecutorService thread pool instead of creating threads manually.
25. What does synchronized do? What is volatile?
synchronized allows only one thread at a time into a block or method on the same lock, protecting shared data. volatile ensures that changes to a variable are visible to all threads, but it does not make compound operations like count++ safe.
26. What is a deadlock?
Two or more threads each wait for a lock the other holds, so none can continue. Avoid it by acquiring locks in a consistent order and keeping locked sections small.
Spring Boot
27. What is Spring Boot and why use it?
Spring Boot makes it fast to build production-ready Spring applications with auto-configuration, embedded servers and starter dependencies, so you write business logic instead of configuration.
28. What does @SpringBootApplication do?
It combines @Configuration, @EnableAutoConfiguration and @ComponentScan: it marks the main configuration class, turns on auto-configuration and scans for components in the package.
29. What is dependency injection? Which type do you prefer?
The framework creates objects and provides (injects) their dependencies instead of the class creating them. Constructor injection is preferred because dependencies are explicit, required and easy to test.
30. @Controller vs @RestController? @Component vs @Service vs @Repository?
@RestController returns data (JSON) directly; @Controller usually returns views. @Service and @Repository are specialised @Component annotations that mark business and data-access layers; @Repository also translates database exceptions.
31. How do you handle exceptions globally in a REST API?
With @RestControllerAdvice and @ExceptionHandler methods that return proper status codes and error messages.
32. What is the N+1 problem in JPA/Hibernate?
Loading a list of entities runs one query, then one extra query per entity to load a related collection. Fix it with fetch joins, entity graphs or batch fetching. Also know lazy vs eager loading.
SQL questions you will almost certainly get
33. Find the second highest value in a column.
One way: SELECT MAX(amount) FROM payments WHERE amount < (SELECT MAX(amount) FROM payments); Also know a window-function approach using DENSE_RANK().
34. INNER JOIN vs LEFT JOIN?
INNER JOIN returns only matching rows from both tables. LEFT JOIN returns all rows from the left table, with NULLs where there is no match on the right.
35. WHERE vs HAVING? What is an index?
WHERE filters rows before grouping; HAVING filters groups after GROUP BY. An index is a data structure that speeds up lookups on a column, at the cost of extra storage and slower writes.
Coding questions to practise
- Reverse a string; check a palindrome; count character frequency using a HashMap.
- Find duplicates in an array; find the first non-repeating character.
- Second largest number in an array without sorting.
- Group a list of employees by department using streams.
- Simple REST endpoint design: "Design APIs for a library system."
For approach and thinking-aloud tips, read how to answer coding and logical reasoning questions.
The project questions (the round decider)
For 1 to 3 years’ experience, the interviewer will spend a lot of time on your project: the architecture, your exact role, a difficult bug you fixed, how you tested, how the code reached production. Prepare this as carefully as the theory. Our guide how to explain your project in an IT interview gives a ready structure.
Frequently Asked Questions
What Java topics are most important for freshers?
Core Java and OOP, String handling, collections (especially HashMap and ArrayList), exceptions, Java 8 features such as streams and lambdas, basic multithreading, SQL and, increasingly, Spring Boot basics.
Is Spring Boot asked in fresher Java interviews?
Often yes, especially for roles that mention Spring. Know dependency injection, key annotations, building a REST API and handling exceptions.
How should I answer the HashMap internal working question?
Explain buckets, hashCode to find the bucket, equals to find the key, how collisions are stored, conversion to a tree for crowded buckets since Java 8, and resizing based on the load factor.
How many coding questions are asked in a Java interview?
Usually one or two in the technical round, from easy to medium level, plus SQL queries. Product companies may ask more and harder problems.
Which Java version should I learn?
Learn on a current long-term support version, and know the Java 8 features (streams, lambdas, Optional) that most interviews still focus on.
