What should you focus on for your Java interview?
Which topics should you review first?
Java basics and strings appeared in 64 of 158 interviews. OOP and backend, testing and tools each appeared in 49 of 158 interviews. Collections and generics followed, in 42 of 158 interviews. Start with these topics, but check more than definitions.
The most asked question was “What is Java, and what are its main features?” Can you answer it clearly? Then check whether you can explain how Java differs from JavaScript, what polymorphism means, and how ArrayList differs from LinkedList. These were also among the most asked questions.
Can you connect strings to thread safety?
Reviewed answers to the StringBuffer and StringBuilder question missed how thread safety affects the choice. Use synchronized StringBuffer for shared modifications across threads and StringBuilder when it is not shared.
Check that you can explain the choice, not just name the classes:
- Which would you choose when multiple threads modify a shared string buffer?
- Which would you choose when the buffer is not shared?
- Can you explain why
Stringis immutable while aStringvariable can still be reassigned?
Can you explain how a map finds a key?
Reviewed HashMap answers missed how a key’s hash becomes a bucket index before the search within that bucket. Include that step when you explain a lookup.
- Can you describe how
hashCodeandequalstake part in storing and finding entries? - Can you explain what breaks in
HashMapwhen theequalsandhashCodecontract is broken? - Can you state clearly that
HashMapis not thread-safe, whileConcurrentHashMapis?
That thread-safety distinction was also missing from reviewed answers. Check that your comparison covers concurrent reads and updates, not just the class names.
What should you check beyond language basics?
The questions also cover concurrency, streams, JVM topics and backend work. Use these checks to find gaps in your answers:
- Can you explain synchronization,
volatileand memory visibility? - Can you describe a stream pipeline and explain what parallel streams are?
- Can you explain garbage collection and name the JVM memory areas?
- Can you describe database access in your Java project?
- Can you explain your experience with Maven, test automation or deployment?
What coding tasks can you use to check yourself?
A code-writing task appeared in 12 of 158 interviews. Use tasks from these interviews to check both your explanation and your code:
- Explain how you would write a palindrome program in Java.
- Write a Java program to reverse a string.
- Refactor Java code to use a lambda expression.
- Sketch Java and MongoDB pseudocode that accepts optional product filters, such as name and price, and returns matching products.
Who gets asked Java
The 20 most asked Java questions
Counted by interview, not by mention: a question asked twice in one conversation counts once.
What is Java, and what are its main features?
Asked in 12 of 158 interviews · last asked Oct 10 · Concept · Junior
Show answer
Java is a high-level, general-purpose programming language built around classes and objects. It is statically typed and uses automatic memory management. Java code usually compiles to bytecode, which runs on a Java Virtual Machine (JVM), allowing the same program to run on different platforms.
- Object-oriented features include encapsulation, inheritance, and polymorphism.
- Bytecode can run on different platforms with a compatible JVM.
- Garbage collection reclaims memory from objects that are no longer reachable.
- Java includes exception handling, multithreading, and a large standard library.
What the interviewer checks: The interviewer is checking whether you understand Java’s basic features and how the JVM supports portability.
Other ways it was asked
- “What is Java?”
- “What are some key features of Java?”
- “What are the key features of Java?”
How do StringBuffer and StringBuilder differ, and which should you use when multiple threads modify strings?
Asked in 8 of 158 interviews · last asked Oct 13 · Concept · Junior
Show answer
StringBuffer and StringBuilder both hold mutable text, but StringBuffer synchronizes its methods and StringBuilder does not. Use StringBuffer when multiple threads modify the same instance; use StringBuilder when each thread has its own instance. StringBuilder usually has less overhead. A sequence of StringBuffer method calls may still need an external lock.
- String is immutable; StringBuffer and StringBuilder can change their contents.
- StringBuffer protects individual method calls, not an entire sequence of calls.
- StringBuilder is usually faster because it has no built-in synchronization.
- Multiple threads can safely use separate StringBuilder instances.
What the interviewer checks: The interviewer checks whether you connect thread safety to shared mutable data and understand synchronization limits.
Common mistake (in 3 of 5 reviewed answers): Many answers forget that sharing the same instance is what makes synchronized StringBuffer the safer choice.
Other ways it was asked
- “What is the difference between String, StringBuilder, and StringBuffer?”
- “What is the difference between StringBuilder and StringBuffer?”
- “What is one key difference between StringBuilder and StringBuffer in Java, and when would you use each?”
How do HashMap and ConcurrentHashMap differ in thread safety and concurrent reads and updates?
Asked in 8 of 158 interviews · last asked Oct 23 · Concept · Mid-level
Show answer
HashMap is not thread-safe; ConcurrentHashMap is. A shared HashMap needs external synchronization when any thread modifies it. ConcurrentHashMap supports concurrent reads and updates; reads generally do not block. Use HashMap for single-threaded or externally synchronized access, and ConcurrentHashMap for shared maps with concurrent updates.
- Separate calls are not automatically atomic; use putIfAbsent, compute, or merge for supported combined operations.
- HashMap allows null keys and values; ConcurrentHashMap allows neither.
- ConcurrentHashMap iterators tolerate concurrent updates but do not provide a fixed snapshot.
What the interviewer checks: The interviewer checks whether you can choose a map for shared access and avoid unsafe update sequences.
Common mistake (in 3 of 6 reviewed answers): Many answers forget that HashMap is not thread-safe, while ConcurrentHashMap is.
Other ways it was asked
- “What is the difference between Java's HashMap and ConcurrentHashMap?”
- “How is HashMap different from ConcurrentHashMap in Java?”
- “Can you explain the difference between HashMap and ConcurrentHashMap?”
What is polymorphism in Java?
Asked in 7 of 158 interviews · last asked Oct 22 · Concept · Junior
Show answer
Polymorphism lets the same operation work with different types. In Java, method overriding provides runtime polymorphism: the actual object's class determines which implementation runs. Method overloading provides compile-time polymorphism: the compiler chooses a method using the declared argument types.
- Overriding works through inheritance or interfaces.
- Overloading uses the same method name with different parameter lists.
- Static methods are hidden, not overridden.
- A broader classification names four types: subtype polymorphism, overloading, parametric polymorphism (generics), and coercion (implicit conversions).
Codeclass Demo { interface Animal { void speak(); } static class Dog implements Animal { public void speak() { System.out.println("Woof"); } } public static void main(String[] args) { Animal animal = new Dog(); animal.speak(); // Runs Dog's implementation } }What the interviewer checks: The interviewer checks whether you understand shared types and can distinguish compile-time method selection from runtime method dispatch.
Other ways it was asked
- “What is polymorphism, and what are two ways to implement it in Java?”
- “What is polymorphism in Java, and how does it work?”
- “What is polymorphism, and how is it expressed in Java?”
How does HashMap store and look up entries using hashCode and equals?
Asked in 7 of 158 interviews · last asked Oct 16 · Concept · Senior
Show answer
HashMap stores entries in an array of buckets. It mixes the key’s hashCode() and uses (capacity - 1) & hash to choose a bucket. Within that bucket, it checks the stored hash, then matches keys by identity or equals(). Collisions use linked lists or, in Java 8+, red-black trees when size thresholds are met.
- Equal keys must have equal hash codes; equal hash codes do not always mean equal keys.
- Putting an equal key replaces its value rather than adding another entry.
- Bucket counts are powers of two; tree conversion also requires a large enough bucket array.
- Lookup is O(1) on average with well-distributed hashes.
What the interviewer checks: The interviewer checks whether you can explain bucket selection, key matching, and collision handling.
Common mistake (in 4 of 7 reviewed answers): Many answers forget that the hash must become a bucket index before HashMap searches for a matching key.
Other ways it was asked
- “How does Java's HashMap work?”
- “How does HashMap work in Java?”
- “How does HashMap handle internal operations in modern Java?”
What is the difference between Java and JavaScript?
Asked in 6 of 158 interviews · last asked Jul 2 · Concept · Junior
Show answer
Java and JavaScript are different languages, despite their similar names. Java is statically typed and usually runs on the JVM; JavaScript is dynamically typed and runs in browsers or environments such as Node.js. I would use Java for backend services and JavaScript for interactive web pages or Node.js services.
- Java checks types at compile time; JavaScript checks types at runtime.
- Java uses class-based inheritance; JavaScript uses prototypes, even when written with class syntax.
- Both can build backend services; JavaScript also runs directly in web browsers.
What the interviewer checks: The interviewer is checking whether you understand their type systems, runtimes, and common uses.
Other ways it was asked
- “What is the difference between Java and JavaScript, and when would you use each?”
- “What is the difference between JavaScript and Java?”
What is the equals and hashCode contract, and what breaks in HashMap if you violate it?
Asked in 6 of 158 interviews · last asked Oct 17 · Concept · Mid-level
Show answer
Objects that are equal by equals must have the same hashCode. If equal keys have different hashes, HashMap may fail to find or remove an entry, or store separate entries for keys that should be equal. Overriding equals without a matching hashCode can cause this bug.
- equals must be reflexive, symmetric, transitive, consistent, and return false for null.
- Unequal objects can have the same hashCode; HashMap uses equals to distinguish them.
- During one execution, hashCode must stay consistent while fields used by equals are unchanged.
- Do not change fields used by equals or hashCode while a key is in the map.
What the interviewer checks: The interviewer checks whether you understand equality rules and how broken or mutable keys affect HashMap lookups.
Other ways it was asked
- “What are equals and hashCode in Java?”
- “What are equals and hashCode in Java, and why are both required?”
- “How do equals and hashCode relate in Java, and what specific bug can happen if you override equals but not hashCode for keys in a HashMap?”
What are the differences between ArrayList and LinkedList in Java?
Asked in 6 of 158 interviews · last asked Oct 16 · Concept · Junior
Show answer
ArrayList uses a resizable array, while LinkedList uses doubly linked nodes. ArrayList gives fast indexed access and usually uses less memory. LinkedList has slower indexed access but constant-time additions and removals at either end. I usually choose ArrayList for a general-purpose list.
- Both implement List; LinkedList also implements Deque for queue and double-ended queue operations.
- Indexed access is O(1) for ArrayList and O(n) for LinkedList.
- ArrayList appends take amortized O(1); middle insertions and removals take O(n) because elements shift.
- LinkedList insertions and removals through an already-positioned iterator take O(1); finding that position can take O(n).
What the interviewer checks: The interviewer checks whether you can connect storage structure to operation costs and choose the right list.
Other ways it was asked
- “What is the difference between ArrayList and LinkedList?”
- “What is the difference between Java's ArrayList and LinkedList?”
- “What is the difference between the List interface and LinkedList in Java?”
What is garbage collection in Java?
Asked in 6 of 158 interviews · last asked Jun 21 · Concept · Junior
Show answer
Garbage collection in Java automatically reclaims heap memory from objects that are no longer reachable. The JVM manages this process, so developers do not free objects manually. Collection uses CPU time and can pause application threads, affecting performance.
- An object can be collected when no path from a GC root reaches it through strong references.
- Collection timing is not guaranteed; System.gc() requests collection but does not force it.
- Keeping references to unused objects can cause memory leaks.
- Garbage collection does not replace closing files or database connections.
What the interviewer checks: The interviewer checks whether you understand object reachability, automatic memory management, and the performance cost of collection.
Other ways it was asked
- “What is garbage collection, and how can it affect the performance of a Java application?”
- “What is garbage collection in .NET?”
- “Can you explain garbage collection?”
What is the difference between == and equals in Java?
Asked in 5 of 158 interviews · last asked Oct 8 · Concept · Junior
Show answer
In Java, `==` compares primitive values or checks whether two references point to the same object. `.equals()` checks equality as defined by the object's class. By default, `Object.equals()` also checks identity, but classes like `String` override it to compare contents.
- Use `==` for primitive value comparisons and object identity checks.
- Use `.equals()` for logical equality when the class defines it.
- Calling `.equals()` on null throws NullPointerException; `Objects.equals(a, b)` handles null safely.
- When overriding `equals()`, also override `hashCode()` so equal objects have equal hash codes.
CodeString a = new String("hello"); String b = new String("hello"); System.out.println(a == b); // false: different objects System.out.println(a.equals(b)); // true: same contentsWhat the interviewer checks: The interviewer is checking whether you distinguish object identity from logical equality and know when to use each.
Other ways it was asked
- “What is the difference between `==` and `.equals()` in core Java?”
- “What is the difference between == and the equals method?”
- “What is the difference between == and .equals()?”
Why is String immutable in Java, and how can a String variable still be reassigned?
Asked in 5 of 158 interviews · last asked Oct 22 · Concept · Junior
Show answer
A String is immutable because its text cannot change after the object is created. This design allows safe sharing, including string pooling and use across threads, and keeps hash codes stable. A String variable holds a reference, so reassigning it changes which object it refers to, not the original object's text.
- String methods such as replace return a result without changing the original object.
- Stable contents make strings reliable HashMap keys.
- A final String variable cannot be reassigned after initialization.
CodeString x = "abc"; String original = x; x = "bcd"; System.out.println(x); // bcd System.out.println(original); // abcWhat the interviewer checks: The interviewer checks whether you distinguish an immutable object from a variable that refers to it.
Other ways it was asked
- “Why is String immutable in Java?”
- “What is string immutability in Java?”
- “Why are Java strings immutable, and what design considerations motivate that immutability?”
How would you design an immutable class in Java?
Asked in 5 of 158 interviews · last asked Oct 6 · Concept · Mid-level
Show answer
An immutable class does not allow its state to change after construction. Make the class final, keep fields private and final, and initialize them in the constructor. Provide no methods that change state, copy mutable inputs, and never expose mutable internal objects through getters.
- A final class prevents subclasses from adding behavior that breaks immutability.
- A final field cannot be reassigned, but its object may still be mutable.
- Use defensive copies for mutable inputs and outputs, including mutable collection elements.
- An unmodifiable collection view alone does not prevent changes through the original collection.
Codeimport java.util.List; // Java 10+: String elements are immutable. public final class Tags { private final List<String> values; public Tags(List<String> values) { this.values = List.copyOf(values); } public List<String> getValues() { return values; } }What the interviewer checks: The interviewer checks whether you can prevent state changes through both methods and shared mutable references.
Other ways it was asked
- “How do you make a class immutable in Java?”
- “Can you explain immutable class design?”
- “What does immutable class design mean in Java?”
What is an interface in Java?
Asked in 5 of 158 interviews · last asked Sep 30 · Concept · Junior
Show answer
An interface in Java is a type that defines a contract for classes to follow. A class uses `implements` and provides the required methods, unless it is abstract. Interfaces let different classes share a common type, so code can use them without depending on a specific implementation.
- A class can implement multiple interfaces.
- Interfaces support polymorphism and make implementations easier to replace or test.
- Interfaces can include abstract methods, default methods, static methods, and constants.
- Default and static methods require Java 8 or later; private interface methods require Java 9 or later.
What the interviewer checks: The interviewer checks whether you understand contracts, implementation, and how interfaces reduce dependencies between classes.
Other ways it was asked
- “What is an interface in Java, and what is it used for?”
- “What advantages do interfaces provide in Java?”
What is the difference between an array and an ArrayList in Java?
Asked in 5 of 158 interviews · last asked Oct 22 · Concept · Junior
Show answer
An array has a fixed length, while an ArrayList can grow or shrink as you add or remove elements. Arrays can hold primitive values or object references. An ArrayList holds only object references, so primitive values use wrapper types such as Integer.
- Use array.length for an array and list.size() for an ArrayList.
- Access array elements with array[index]; use get(index) and set(index, value) for an ArrayList.
- ArrayList implements the List interface; List defines operations, while ArrayList provides an implementation.
- Both provide fast access by index, but ArrayList may shift elements when inserting or removing.
What the interviewer checks: The interviewer checks whether you understand fixed length, resizing, element types, and the difference between List and ArrayList.
Other ways it was asked
- “What is the difference between an array and an ArrayList?”
- “What is the difference between ArrayList and List in Java?”
- “How is an array different from an ArrayList?”
How does HashMap handle collisions, and how did Java 8 change this with treeified buckets?
Asked in 5 of 158 interviews · last asked Oct 17 · Concept · Mid-level
Show answer
HashMap stores colliding keys in the same bucket and checks key equality to find the right entry. Before Java 8, buckets used linked lists. Java 8 added red-black trees for crowded buckets to make collision-heavy lookups faster.
- OpenJDK Java 8 put treeifies on the ninth bucket entry when table capacity is at least 64.
- Below that capacity, HashMap expands the table instead of treeifying the bucket.
- Tree lookup is usually O(log n), but equal-hash, non-comparable keys can still require O(n).
- Equal keys replace existing values; sharing a bucket does not make keys equal.
What the interviewer checks: The interviewer checks whether you understand collisions, treeification conditions, and the limits of the performance improvement.
Other ways it was asked
- “How did HashMap improve collision handling after Java 8?”
- “What changed in HashMap collision handling after Java 8?”
- “In Java, explain how HashMap handles collisions internally, and what changes when a bucket gets treeified.”
What are exceptions in Java, and how are they handled?
Asked in 5 of 158 interviews · last asked Oct 5 · Concept · Junior
Show answer
Exceptions are objects that signal problems and interrupt normal program flow. Java uses try blocks for code that may fail and catch blocks to handle matching exceptions. If no catch matches, the exception passes to the caller. A finally block normally runs whether an exception occurs or not, often for cleanup.
- Checked exceptions must be caught or declared with throws.
- RuntimeException and its subclasses are unchecked; catching or declaring them is optional.
- throw raises an exception; throws declares exceptions a method may pass to its caller.
- Use try-with-resources to automatically close resources, even when an exception occurs.
What the interviewer checks: The interviewer checks whether you understand exception flow, checked versus unchecked exceptions, and safe cleanup.
Other ways it was asked
- “How do you handle exceptions in Java?”
- “What is an exception in Java?”
- “What are exceptions in Java?”
What is a functional interface in Java, and can you give examples?
Asked in 5 of 158 interviews · last asked Oct 16 · Concept · Junior
Show answer
A functional interface is an interface with one abstract method to implement. Examples include Runnable, Predicate<T>, and Function<T, R>. Java 8 supports implementing these interfaces with lambda expressions or method references. Functional interfaces such as Runnable existed in Java 7, but Java 7 did not support lambdas.
- @FunctionalInterface is optional, but it makes the compiler check that the interface meets the rule.
- Default and static methods do not count toward the single abstract method.
- Methods matching public methods of Object, such as equals, do not count either.
CodeRunnable task = () -> System.out.println("Running"); task.run();What the interviewer checks: The interviewer checks whether you understand the single abstract method rule and how it enables lambdas.
Other ways it was asked
- “What is a functional interface in Java?”
- “What is a functional interface?”
- “What are functional interfaces in Java 8? Can you give some examples?”
What does volatile guarantee in Java, and why doesn't it make operations atomic?
Asked in 5 of 158 interviews · last asked Oct 16 · Concept · Mid-level
Show answer
In Java, `volatile` guarantees visibility and ordering: a write happens-before subsequent reads of that field. Individual reads and writes are atomic, but compound operations such as `count++` are not. An increment reads, adds, and writes in separate steps, so threads can interfere. Use synchronization or an atomic class for such updates.
- A volatile write also makes earlier writes visible to a thread that subsequently reads that volatile field.
- Volatile does not lock anything or prevent threads from running at the same time.
- Use `AtomicInteger.incrementAndGet()` or synchronization for a shared counter.
- A volatile reference does not make the referenced object's fields volatile.
What the interviewer checks: The interviewer is checking whether you distinguish visibility and ordering from atomicity.
Other ways it was asked
- “What is the role of the volatile keyword in Java?”
- “What does volatile do in Java?”
- “Can you tell me about the volatile keyword?”
How does the JVM organize and manage memory, including the heap, stack, and Metaspace?
Asked in 5 of 158 interviews · last asked Oct 22 · Concept · Mid-level
Show answer
The JVM separates memory into areas with different roles. The shared heap holds objects and arrays, and garbage collection reclaims unreachable objects. Each thread has a stack of method frames holding local variables and call data. In HotSpot since Java 8, Metaspace holds class metadata in native memory, outside the heap.
- Stack frames are removed when methods finish; heap objects can outlive the methods that created them.
- Deep method calls can cause StackOverflowError; exhausted heap or Metaspace can cause OutOfMemoryError.
- Metaspace replaced PermGen; class unloading can reclaim its metadata.
- The Java Memory Model defines thread visibility and ordering rules, not these memory areas.
What the interviewer checks: The interviewer checks whether you understand memory areas, their lifetimes, and how garbage collection differs from stack cleanup.
Other ways it was asked
- “How is memory structured inside the Java JVM?”
- “How does the JVM memory model work?”
- “Can you explain what is Java memory model?”
What is inheritance, and what types of inheritance does Java support?
Asked in 4 of 158 interviews · last asked Sep 27 · Concept · Junior
Show answer
Inheritance lets a class reuse and extend another class's fields and methods using `extends`. Java supports single, multilevel, and hierarchical class inheritance. A class can extend only one class, but it can implement multiple interfaces. An interface can also extend multiple interfaces.
- Single: one class directly extends one parent class.
- Multilevel: inheritance forms a chain, such as Animal → Dog → Puppy.
- Hierarchical: several classes extend the same parent class.
- Interfaces support multiple inheritance of type and can be combined with class inheritance.
What the interviewer checks: The interviewer checks whether you understand inheritance patterns and the different rules for classes and interfaces.
Other ways it was asked
- “Which types of inheritance does Java support?”
- “What is inheritance in Java?”
- “How do you achieve inheritance in Java?”
Java basics and strings interview questions
Questions cover Java’s features, language comparisons, syntax, types, variables, methods, strings, numeric precision and how references behave. 58 questions.
What is the difference between final, finally, and finalize in Java?
Asked in 3 of 158 interviews · last asked Sep 12 · Concept · Junior
Other ways it was asked
- “What is the difference between final, finally, and finalize?”
- “What is the difference between `final`, `finally`, and `finalize`?”
- “What is the difference between final, finally, and finalize, and what does each mean?”
What is the difference between Java and Python?
Asked in 3 of 158 interviews · last asked Oct 12 · Concept · Junior
Other ways it was asked
- “What is the difference between JavaScript and Python?”
- “What is the difference between Python and Java?”
What is the `this` keyword used for in Java?
Asked in 2 of 158 interviews · last asked Aug 18 · Concept · Junior
Other ways it was asked
- “Why and when is the `this` keyword used in Java?”
- “What is the purpose of the `this` keyword in Java?”
What is the use of the final keyword in Java?
Asked in 2 of 158 interviews · last asked Sep 4 · Concept · Junior
Other ways it was asked
- “What does the final keyword do when applied to a method in Java?”
- “What does the final keyword do when applied to a class in Java?”
- “What is a final variable in Java, and what does the final keyword do?”
Can you explain what a string is in Java?
Asked in 2 of 158 interviews · last asked Jul 24 · Concept · Junior
Other ways it was asked
- “What is a String in Java?”
What is the difference between an instance variable and a class variable in Java?
Asked in 2 of 158 interviews · last asked Jul 16 · Concept · Junior
Other ways it was asked
- “What is an instance variable in Java?”
What are the technical differences between Java and C#, and when is each more useful?
Asked once · last asked Jun 26 · Concept · Mid-level
Other ways it was asked
- “What are the technical differences between Java and C#, and when would you choose one over the other?”
If a list reference is declared final in Java, can the list's contents still be changed?
Asked once · last asked Mar 25 · Concept · Mid-level
Where would you use StringBuilder and StringBuffer in Java?
Asked once · last asked Apr 17 · Concept · Junior
Which Java type should you use to represent money?
Asked once · last asked May 25 · Concept · Junior
What is the difference between creating a string with new and using a string literal in Java?
Asked once · last asked Jul 16 · Concept · Mid-level
How does BigDecimal differ from float and double in Java?
Asked once · last asked Jul 16 · Concept · Mid-level
Java OOP interview questions
Explore classes, constructors, inheritance, interfaces and polymorphism, plus access modifiers, immutability, object contracts, annotations, reflection and design patterns. 58 questions.
Can a static method be overridden?
Asked in 4 of 158 interviews · last asked Oct 18 · Concept · Junior
Other ways it was asked
- “Can you override a static method in Java?”
- “Can static methods be overridden?”
- “Why can't static methods be overridden in Java?”
Can you explain how Java handles multiple inheritance?
Asked in 4 of 158 interviews · last asked Oct 8 · Concept · Junior
Other ways it was asked
- “How can you implement multiple inheritance in Java?”
- “How can you achieve multiple inheritance in Java when classes do not support it?”
- “Why does Java not allow multiple inheritance?”
What is method overriding in Java?
Asked in 4 of 158 interviews · last asked Jul 16 · Concept · Junior
Other ways it was asked
- “What is method overloading in Java?”
- “How does method overriding work in Java?”
How does the hashCode() method work in Java?
Asked in 3 of 158 interviews · last asked Sep 16 · Concept · Mid-level
Other ways it was asked
- “What does the `hashCode` method do in Java?”
- “How is the hash code calculated in Java?”
- “How does Java calculate the hash code of a String?”
What are the core OOP principles in Java, and how would you apply them in a real example?
Asked in 3 of 158 interviews · last asked Oct 19 · Concept · Junior
Other ways it was asked
- “Could you explain the core principles of object-oriented programming and provide a real-world example of how you have applied them in Java?”
- “Could you explain the four main OOP principles in Java, with a quick example of each?”
- “Can you explain OOP concepts in Java and give a small scenario where they make sense?”
What are the differences between sealed and non-sealed classes in Java?
Asked in 2 of 158 interviews · last asked Sep 2 · Concept · Mid-level
Other ways it was asked
- “What do sealed classes do in Java?”
Why would you choose a Java record over a class?
Asked in 2 of 158 interviews · last asked Sep 22 · Concept · Junior
Other ways it was asked
- “How do Java records differ from standard classes?”
What is reflection in Java?
Asked in 2 of 158 interviews · last asked Apr 23 · Concept · Junior
What are annotations in Java, and what types are there?
Asked in 2 of 158 interviews · last asked Apr 23 · Concept · Junior
What is abstraction in Java?
Asked in 2 of 158 interviews · last asked Sep 9 · Concept · Junior
Other ways it was asked
- “In Java, how do you implement abstraction?”
Can interfaces have static methods in Java?
Asked once · last asked Sep 11 · Concept · Junior
Other ways it was asked
- “Can a functional interface have default and static methods?”
- “Can a functional interface have static methods?”
- “Why can static methods be defined in a Java interface?”
Can you give an example showing when to use an interface versus an abstract class in Java?
Asked once · last asked Sep 27 · Concept · Junior
Java collections and generics interview questions
Check your understanding of arrays, collection interfaces and implementations, hashing, map internals, iterators, sorting, generics and performance. 44 questions.
In Java, how does an ArrayList grow internally when it runs out of capacity, and what happens to existing elements during that growth?
Asked in 4 of 158 interviews · last asked Oct 22 · Concept · Mid-level
Other ways it was asked
- “In Java, when an ArrayList grows past capacity, what happens to its backing storage and what does that imply for existing element references and indices?”
- “In Java, what happens internally when you add an element to an ArrayList beyond its current capacity? How is the backing array resized, and how are existing elements moved?”
- “What is the default capacity of a Java ArrayList, and how does it grow when you add more elements?”
What is the Java Collections Framework, and what collections does it provide?
Asked in 4 of 158 interviews · last asked Sep 8 · Concept · Junior
Other ways it was asked
- “Can you explain the Java Collections Framework?”
- “What is the Java Collections Framework, and what are its main components?”
- “Can you tell me what the Java collections are?”
What are the differences between List, Set, Queue, and Map in Java?
Asked in 3 of 158 interviews · last asked Oct 8 · Concept · Junior
Other ways it was asked
- “What is the difference between a List, a Set, and a Map?”
- “What is the difference between List and Set?”
- “What is the difference between List, Queue, and Set in Java?”
What is a HashMap?
Asked in 3 of 158 interviews · last asked May 1 · Concept · Junior
Other ways it was asked
- “What is a HashMap in Java?”
What is the difference between a HashMap and a HashSet?
Asked in 2 of 158 interviews · last asked Jul 31 · Concept · Junior
How is LinkedList implemented internally, and what memory overhead do its node references add compared with ArrayList?
Asked in 2 of 158 interviews · last asked Oct 17 · Concept · Mid-level
Other ways it was asked
- “How is a LinkedList implemented internally in Java?”
- “In Java, how is a LinkedList node structured, what references does it hold, and what extra memory cost does that imply per element versus an ArrayList?”
In a HashMap, what exactly happens during a resize or rehash, how are buckets redistributed, and what determines which bucket an existing entry moves to?
Asked in 2 of 158 interviews · last asked Oct 17 · Concept · Senior
Other ways it was asked
- “In Java, what happens during HashMap resizing and rehashing? How are entries redistributed across the new table without recomputing every hash from scratch?”
What do you understand by hashing in Java?
Asked in 2 of 158 interviews · last asked Sep 16 · Concept · Junior
Other ways it was asked
- “What is hashing in Java?”
What characterizes a good HashMap key, how does a HashMap work, what is a collision, and what contract must keys follow?
Asked once · last asked Mar 6 · Concept · Mid-level
If an object used as a HashMap key changes a field that contributes to its hash code, what happens?
Asked once · last asked Mar 25 · Scenario · Mid-level
What is the difference between a LinkedList and a HashMap?
Asked once · last asked Apr 8 · Concept · Junior
What is the difference between a cache and a Java Map, and when would you use each?
Asked once · last asked Apr 23 · Concept · Junior
Java exception handling interview questions
Review the exception hierarchy, checked and unchecked exceptions, throwing and catching, finally blocks and error-handling choices. 15 questions.
What is the difference between checked and unchecked exceptions?
Asked in 4 of 158 interviews · last asked Jul 24 · Concept · Junior
Other ways it was asked
- “What is your opinion of checked versus unchecked exceptions?”
- “What is the difference between checked and unchecked exceptions in Java?”
- “Can you tell me the difference between checked and unchecked exceptions?”
How is Java's exception hierarchy organized, and how do Throwable, Exception, and Error relate?
Asked in 2 of 158 interviews · last asked Jul 16 · Concept · Junior
Other ways it was asked
- “What is the relationship between Throwable, Exception, and Error in Java, and what other types of exceptions are there?”
- “How is the exception hierarchy structured in Java?”
What is a `finally` block in Java exception handling?
Asked in 2 of 158 interviews · last asked Oct 8 · Concept · Junior
Other ways it was asked
- “What is the purpose of the finally block in Java?”
Are try, catch, and throws the only mechanisms used for exception handling in Java?
Asked once · last asked Apr 23 · Concept · Junior
How do you handle exceptions in a Spring Batch process?
Asked once · last asked May 29 · Scenario · Mid-level
When are checked exceptions verified in Java, and how does the compiler know a method may throw one?
Asked once · last asked Jul 16 · Concept · Mid-level
What is the difference between throw, throws, and Throwable?
Asked once · last asked Sep 30 · Concept · Junior
What can prevent a Java `finally` block from executing?
Asked once · last asked Oct 8 · Concept · Mid-level
In Java, how would you choose between throwing a checked exception, throwing an unchecked exception, or returning an Optional- or Either-style result?
Asked once · last asked Oct 20 · Concept · Mid-level
In Java, how do you typically structure exception handling in a Spring Boot REST API?
Asked once · last asked Oct 24 · Tooling · Mid-level
Other ways it was asked
- “In Java, how do you typically structure exception handling in a Spring Boot REST API so errors are consistent, secure, and easy for clients to consume?”
What is the difference between try-catch and throw in Java?
Asked once · last asked Apr 23 · Concept · Junior
How does the `try-catch-finally` construct work in Java?
Asked once · last asked Jul 22 · Concept · Junior
Show 2 more
If you do not need cleanup code, do you need to include a `finally` block in Java?
Asked once · last asked Oct 8 · Concept · Junior
How do you handle exceptions from a Callable?
Asked once · last asked Oct 16 · Concept · Mid-level
Java streams, lambdas and Java 8 interview questions
Work through questions on functional programming, functional interfaces, lambdas, stream pipelines, parallel streams, Optional and newer Java features. 29 questions.
What is the difference between map and flatMap in Java streams?
Asked in 4 of 158 interviews · last asked Oct 22 · Concept · Mid-level
Other ways it was asked
- “What is the difference between the map and flatMap methods in Java Streams?”
- “What is the difference between the map method and the flatMap method in the Stream API?”
- “What does flatMap do in the Java Stream API, and when would you use it?”
What new features were introduced in Java 8 that were not in Java 7?
Asked in 4 of 158 interviews · last asked Oct 13 · Concept · Mid-level
Other ways it was asked
- “What new features were introduced in Java 8, 11, and 17?”
- “What features were introduced in Java 8?”
- “Can you give a few examples of Java 8 features?”
What is the Java Streams API, and when would you use it?
Asked in 3 of 158 interviews · last asked Jul 16 · Concept · Mid-level
Other ways it was asked
- “What is the Java Stream API?”
- “What should you consider when using the Java Stream API?”
What are the use cases for Optional in Java, and when should you not use it?
Asked in 2 of 158 interviews · last asked Sep 2 · Concept · Mid-level
Other ways it was asked
- “What is Optional in Java, and in what scenarios would you use it?”
Which improvements between Java 17 and Java 21 would you use, and how do they help?
Asked in 2 of 158 interviews · last asked Jun 15 · Concept · Senior
Other ways it was asked
- “Which recent versions of Java have you used, and what impact did they have on your projects, especially Java 21?”
- “What are three notable improvements in Java between versions 17 and 21?”
What is a Java Predicate, what type of value does it take, and how would you implement one?
Asked in 2 of 158 interviews · last asked Oct 13 · Concept · Mid-level
Other ways it was asked
- “What is a predicate in Java?”
What are Java streams, and why can using a parallel stream be dangerous?
Asked in 2 of 158 interviews · last asked Sep 2 · Concept · Senior
Other ways it was asked
- “How do streams differ from collections, and what are the dangers of using parallel streams?”
What is functional programming?
Asked in 2 of 158 interviews · last asked Sep 11 · Concept · Junior
What is a lambda expression in Java?
Asked in 2 of 158 interviews · last asked Jul 16 · Concept · Junior
What operations are available in the Java Stream API?
Asked in 2 of 158 interviews · last asked Oct 22 · Concept · Mid-level
Other ways it was asked
- “What filtering operations are available in the Java Stream API?”
What is the difference between a stream and a collection in Java?
Asked once · last asked May 12 · Concept · Junior
What is a functional interface, and what is the difference between an abstract class and an interface?
Asked once · last asked Mar 16 · Concept · Junior
Show 16 more
Which features introduced between Java 11 and Java 17 would you use in real projects, and what concrete benefits do they provide?
Asked once · last asked May 19 · Concept · Mid-level
Other ways it was asked
- “Which features introduced between Java 11 and Java 17 have you used in real projects, and what concrete benefits do they provide?”
What is the difference between calling stream().parallel() and parallelStream() in Java?
Asked once · last asked Jun 15 · Concept · Mid-level
What are the stages of a Java Stream API pipeline, and in what order do they run?
Asked once · last asked Jul 16 · Concept · Mid-level
How would you refactor Java code to use a lambda expression?
Asked once · last asked Sep 2 · Write code · Junior
Why must a local variable used inside a lambda be effectively final?
Asked once · last asked Sep 2 · Concept · Mid-level
Why do we need the functional interface annotation?
Asked once · last asked Sep 11 · Concept · Mid-level
When reviewing code that uses Optional, what are the main misuses you look for that can hurt code quality or correctness?
Asked once · last asked Oct 20 · Scenario · Mid-level
What is the Stream API?
Asked once · last asked Apr 17 · Concept · Junior
Is the Java Stream API related to time and space complexity?
Asked once · last asked Apr 17 · Concept · Mid-level
What is Optional in Java 8?
Asked once · last asked Apr 17 · Concept · Junior
In which Java version were records introduced as a permanent feature?
Asked once · last asked May 12 · Concept · Junior
Other ways it was asked
- “Were records introduced in Java 17 or Java 11?”
What is the difference between a Java Stream and the Stream filter method?
Asked once · last asked Jun 12 · Concept · Junior
What are three functional interfaces that you can use with Java Streams?
Asked once · last asked Jun 15 · Concept · Junior
How would you explain the relationship between a functional interface and functional programming to someone without programming knowledge?
Asked once · last asked Sep 11 · Concept · Mid-level
What is the Optional class in Java?
Asked once · last asked Oct 16 · Concept · Junior
Other ways it was asked
- “What is an Optional class?”
What methods can I use with Optional?
Asked once · last asked Oct 16 · Concept · Junior
Java multithreading and concurrency interview questions
These questions cover threads, executors, futures, synchronization, volatile, atomics, memory visibility, concurrent collections, ThreadLocal and virtual threads. 45 questions.
When should you use volatile, synchronized, or atomic variables, and what guarantees does each provide?
Asked in 4 of 158 interviews · last asked Oct 17 · Concept · Senior
Other ways it was asked
- “In Java, what are the key differences between volatile, synchronized, and AtomicInteger regarding visibility, atomicity, and ordering guarantees?”
- “In Java, what's the difference between volatile and synchronized in terms of visibility, atomicity, and ordering?”
- “In Java, what's the difference between volatile and synchronized regarding visibility and atomicity, and when would you choose one over the other?”
What is multithreading in Java, and how does it work?
Asked in 3 of 158 interviews · last asked Sep 4 · Concept · Mid-level
Other ways it was asked
- “What is multithreading in Java, and when would you use it?”
- “What is multithreading, and when is it useful?”
What is a synchronized block in Java?
Asked in 3 of 158 interviews · last asked Sep 11 · Concept · Junior
Other ways it was asked
- “What does a synchronized block or method lock in Java?”
- “What is the difference between a synchronized method and a synchronized block in Java?”
What is the use of ConcurrentHashMap?
Asked in 3 of 158 interviews · last asked Oct 6 · Concept · Mid-level
Other ways it was asked
- “Why do we need ConcurrentHashMap?”
- “How does ConcurrentHashMap work internally?”
How do you manage concurrency and threads in Java?
Asked in 2 of 158 interviews · last asked Jun 15 · Concept · Senior
Other ways it was asked
- “Can you explain concurrency and thread management in Java?”
What is the difference between Future and CompletableFuture?
Asked in 2 of 158 interviews · last asked Oct 16 · Concept · Mid-level
What are virtual threads, how do they differ from platform threads, and what problems do they solve?
Asked in 2 of 158 interviews · last asked Apr 13 · Concept · Senior
Other ways it was asked
- “What is the difference between a Java virtual thread and a platform thread?”
- “What are virtual threads, and what problems do they help solve?”
- “Besides allowing many threads to be created, what problem do virtual threads solve?”
What is a thread in Java and Kotlin?
Asked in 2 of 158 interviews · last asked Oct 2 · Concept · Junior
Other ways it was asked
- “What is a thread in Java?”
How does Java's AtomicInteger work, and what principles does it rely on?
Asked once · last asked Apr 13 · Concept · Senior
In ConcurrentHashMap, is a lock applied to the entire map or only to part of it?
Asked once · last asked Apr 13 · Concept · Senior
If a static synchronized method is called concurrently on different objects, can multiple threads enter its critical section at the same time?
Asked once · last asked Apr 13 · Concept · Senior
What is the difference between Runnable and Thread?
Asked once · last asked Apr 17 · Concept · Junior
Java JVM, memory management and performance interview questions
Look at the JDK, runtime, bytecode, JIT compilation, JVM memory, garbage collection, profiling, dumps and finding production problems. 18 questions.
What is the difference between the JDK, JRE, and JVM?
Asked in 4 of 158 interviews · last asked Sep 27 · Concept · Junior
Other ways it was asked
- “What are the JVM, JRE, and JDK?”
- “What are the JDK, JRE, and JVM in Java?”
- “What is the difference between the JVM and the JDK?”
What is JIT compilation?
Asked in 3 of 158 interviews · last asked Sep 28 · Concept · Junior
Other ways it was asked
- “What is a JIT compiler in Java?”
- “What is JIT compilation, and how does it differ from ahead-of-time compilation?”
If you have an application running as a JAR file on Linux that crashes every one to three months, what might be causing it?
Asked once · last asked Apr 9 · Scenario · Mid-level
How would you capture a Java heap dump or heap histogram to investigate memory usage?
Asked once · last asked Apr 13 · Tooling · Senior
How do you profile a Java application to investigate memory or performance issues?
Asked once · last asked May 25 · Scenario · Mid-level
When a Java application logs an error, how do you investigate and resolve it?
Asked once · last asked May 25 · Scenario · Mid-level
Can you explicitly trigger garbage collection in Java, and is it guaranteed to run?
Asked once · last asked Jul 16 · Concept · Mid-level
What was Java's finalize() method intended for, and how did it work?
Asked once · last asked Sep 4 · Concept · Mid-level
How does Java distinguish heap and stack memory, and what is each used for?
Asked once · last asked Sep 22 · Concept · Mid-level
What is bytecode in Java?
Asked once · last asked Jul 16 · Concept · Junior
What is the Java heap, and how is it used?
Asked once · last asked Jul 16 · Concept · Junior
What is the JDK in Java?
Asked once · last asked Jul 31 · Concept · Junior
Show 4 more
How do you optimize Java application performance?
Asked once · last asked Aug 4 · Scenario · Mid-level
Can you explain the architecture of Java, including what JRE and JDK mean?
Asked once · last asked Sep 18 · Concept · Junior
What do you understand about the JVM?
Asked once · last asked Sep 28 · Concept · Junior
What does JIT stand for?
Asked once · last asked Sep 28 · Concept · Junior
Java backend, testing and tools interview questions
Backend questions cover database access, Spring, web frameworks, integrations, Maven, testing, security, deployment, high availability and project experience. 71 questions.
What is the difference between Maven and Gradle?
Asked in 2 of 158 interviews · last asked Oct 23 · Concept · Junior
Other ways it was asked
- “What are the differences between Maven and Gradle?”
What is JPA, and what are its types?
Asked in 2 of 158 interviews · last asked Jul 21 · Concept · Junior
Other ways it was asked
- “What is JPA?”
What is JDBC?
Asked in 2 of 158 interviews · last asked Jul 21 · Concept · Junior
Tell me about Maven.
Asked in 2 of 158 interviews · last asked Jun 17 · Concept · Junior
Other ways it was asked
- “Can you explain Maven?”
What does Spring use under the hood to create proxies for transactions?
Asked once · last asked Jul 16 · Concept · Senior
Other ways it was asked
- “How does Spring's proxy-based transaction management work under the hood?”
How would you mock a static class, a controller or URL, and a regular class in Java?
Asked once · last asked Feb 14 · Scenario · Senior
How do you manage dependencies and their versions in a Java application?
Asked once · last asked Feb 14 · Tooling · Mid-level
How does the JPA entity lifecycle work, and what states can an entity have?
Asked once · last asked Mar 2 · Concept · Mid-level
What is the difference between JPA and JDBC, and when would you use each?
Asked once · last asked Mar 6 · Concept · Mid-level
How can a Java server interact with Python machine-learning libraries?
Asked once · last asked Mar 16 · Concept · Mid-level
How do embedded adapters and REST APIs differ when integrating Python libraries with a Java server?
Asked once · last asked Mar 16 · Concept · Mid-level
How would you use Java and MongoDB to build a high-performance application that accepts optional filters, such as product name and price, and returns matching products? Describe the approach in pseudocode.
Asked once · last asked Mar 20 · Write code · Senior
Java coding interview questions
Try hands-on exercises with strings, arrays, numbers, collections, sorting, stream transformations and data structures. 15 questions.
Can you explain how to write a palindrome program in Java?
Asked in 2 of 158 interviews · last asked Jul 23 · Write code · Junior
Other ways it was asked
- “Can you write a basic Java program to check for a palindrome?”
- “Write a Java program to check whether a string is a palindrome.”
Write a Java program to reverse a string.
Asked once · last asked Jul 23 · Write code · Junior
Write a Java program to generate a random alphanumeric string with a length greater than six characters.
Asked once · last asked Mar 24 · Write code · Junior
Can you write a Java program for finding prime numbers?
Asked once · last asked Jul 22 · Write code · Junior
Can you write a Java program for swapping numbers in an array?
Asked once · last asked Jul 22 · Write code · Junior
Write a Java program to find prime numbers in a matrix.
Asked once · last asked Jul 23 · Write code · Junior
Could you implement a stack in Java?
Asked once · last asked Aug 5 · Write code · Junior
Write code for the four-sum problem in Java.
Asked once · last asked Sep 6 · Write code · Junior
Find the duplicates in an array using Java.
Asked once · last asked Sep 6 · Write code · Junior
How do you use Java streams to convert a list of employees into a map?
Asked once · last asked Oct 5 · Write code · Mid-level
Write Java code to remove duplicate elements from a list.
Asked once · last asked Oct 16 · Write code · Mid-level
How would you compare Person objects by age when sorting them in descending order in Java?
Asked once · last asked Oct 2 · Concept · Junior
Show 3 more
How would you find the largest number in a Java array?
Asked once · last asked Oct 24 · Write code · Junior
Other ways it was asked
- “How can you use a temporary variable to find the largest number in a Java array?”
Inside the main method, can you define an integer array with five elements?
Asked once · last asked Oct 24 · Write code · Junior
How can you print the elements of a Java array without using a for loop?
Asked once · last asked Oct 24 · Write code · Junior
Live coding round next? Coding mode in the MeetAssist desktop app solves the problem on your screen, with your phone as the remote.
Related interview questions
- Software Engineer interview questions
- QA Engineer interview questions
- DevOps Engineer interview questions
- Data Engineer interview questions
- Data Analyst interview questions
- Python interview questions
- JavaScript interview questions
- TypeScript interview questions
- C# and .NET interview questions
- C++ interview questions
- PHP and Laravel interview questions
How this list is made
Every question here was asked by a real interviewer in a real job interview that a candidate ran MeetAssist in. After the call, the interviewer's questions are pulled from the transcript. Practice sessions, tests, exams and anything that was not a job interview are dropped.
Questions are rewritten so they make sense on their own: names of people, employers and clients are removed, and speech-to-text mistakes are fixed. Small talk, logistics and questions about one candidate's own résumé are left out. Rephrasings of the same question are merged, and the count is the number of different interviews it came up in.
The interviews come from candidates who use MeetAssist, so they lean towards software, data and AI roles: the shares describe these interviews, not every Java interview. Answers to the most asked questions are written and checked by an editor; a "common mistake" is shown only when reviews of real answers in these interviews show it, with the count.
158 interviews, 100 candidates, Sep 2025 to Oct 2026. Updated every month with new interviews.
Or add the Chrome extension