PUBLIC QUESTION PREVIEW
Java interview questions
JVM, collections, concurrency, Spring basics, generics, streams.
Showing 12 of 50 source questions. Sample answers are study material, not employer-specific hiring guidance.
How to work through this preview
Attempt each question before reading its answer. For a concept, give a definition and a concrete example. For code, state constraints, walk through a small input, and check complexity. For design, separate requirements from assumptions and explain failure handling. Use real situations for behavioral answers.
QUESTION 1 / medium / conceptual
What is the difference between HashMap and ConcurrentHashMap?
Sample answer
Hints to guide your next attempt
- Thread safety
- ConcurrentHashMap uses segment-level locking
Source tags: hashmap / concurrency / thread-safety / java
QUESTION 2 / easy / conceptual
What is the difference between checked and unchecked exceptions in Java?
Sample answer
Hints to guide your next attempt
- Checked exceptions must be handled or declared
- RuntimeException and its subclasses are unchecked
Source tags: exceptions / checked / unchecked / error-handling / java
QUESTION 3 / medium / conceptual
How does the Java garbage collector work? What is a memory leak in Java?
Sample answer
Hints to guide your next attempt
- GC traces reachability from GC roots
- Memory leaks happen when objects are reachable but no longer needed
Source tags: garbage-collection / memory-leak / jvm / java
QUESTION 4 / easy / conceptual
What is the difference between == and .equals() in Java?
Supplied choices
- == compares content; .equals() compares references
- They are identical for String comparisons
- == compares references (memory address) for objects; .equals() compares logical content if overridden
- .equals() is only defined on String — other classes use == for equality
Source answer choice: C. == compares references (memory address) for objects; .equals() compares logical content if overridden
Sample answer
Hints to guide your next attempt
- == compares references for objects
- .equals() compares content (if overridden)
Source tags: equality / string / java
QUESTION 5 / easy / conceptual
What is the Java Collections Framework? When do you use List vs Set vs Map?
Sample answer
Hints to guide your next attempt
- List = ordered, duplicates allowed; Set = unique elements; Map = key-value pairs
Source tags: collections / list / set / map / java
QUESTION 6 / medium / conceptual
What are Java Streams? Explain lazy evaluation, intermediate vs terminal operations.
Sample answer
Hints to guide your next attempt
- Streams are lazy — nothing executes until a terminal operation
- Intermediate operations return Stream; terminal operations produce a result
Source tags: streams / lambda / lazy-evaluation / java-8 / java
QUESTION 7 / easy / conceptual
Why is String immutable in Java? What is the String pool?
Supplied choices
- String is mutable — it uses a char[] internally that can be modified
- String is immutable for performance only — thread safety is handled separately
- String is immutable to enable pool interning, thread-safety, and hashcode caching; any modification creates a new object
- String pool stores all String objects regardless of how they were created
Source answer choice: C. String is immutable to enable pool interning, thread-safety, and hashcode caching; any modification creates a new object
Sample answer
Hints to guide your next attempt
- Immutability enables safe sharing and caching
- String literals are interned — stored in the pool
Source tags: string / immutability / string-pool / interning / java
QUESTION 8 / easy / conceptual
What is the difference between an interface and an abstract class in Java?
Supplied choices
- Abstract classes allow multiple inheritance; interfaces allow only single inheritance
- Interfaces can have constructors; abstract classes cannot
- Abstract classes can have state and constructors; interfaces define contracts; a class can implement multiple interfaces but extend only one class
- There is no practical difference in Java 8+ since interfaces can have default methods
Source answer choice: C. Abstract classes can have state and constructors; interfaces define contracts; a class can implement multiple interfaces but extend only one class
Sample answer
Hints to guide your next attempt
- Multiple inheritance of interfaces vs single class inheritance
- Java 8 default methods blurred the line
Source tags: interface / abstract-class / inheritance / java
QUESTION 9 / medium / conceptual
What is the synchronized keyword in Java? When would you use volatile instead?
Sample answer
Hints to guide your next attempt
- synchronized = mutual exclusion + memory visibility
- volatile = memory visibility only, no atomicity
Source tags: synchronized / volatile / concurrency / thread-safety / java
QUESTION 10 / easy / conceptual
What is the difference between Comparable and Comparator in Java?
Supplied choices
- Comparable is for custom objects; Comparator is only for primitives
- Both are identical — Comparator is just a lambda-friendly version of Comparable
- Comparable defines natural ordering within the class (one ordering); Comparator is external and allows multiple orderings
- Comparator is deprecated in Java 8+ — use Comparable instead
Source answer choice: C. Comparable defines natural ordering within the class (one ordering); Comparator is external and allows multiple orderings
Sample answer
Hints to guide your next attempt
- Comparable = natural order (intrinsic to the class)
- Comparator = external, flexible ordering
Source tags: comparable / comparator / sorting / java
QUESTION 11 / medium / conceptual
What is Optional in Java 8? How does it prevent NullPointerException?
Supplied choices
- Optional is a replacement for null — always use it instead of returning null
- Optional eliminates NullPointerException by making the compiler enforce null checks
- Optional explicitly represents absence in a return type, forcing callers to handle the empty case through its API
- Optional should be used as method parameters to indicate optional arguments
Source answer choice: C. Optional explicitly represents absence in a return type, forcing callers to handle the empty case through its API
Sample answer
Hints to guide your next attempt
- Optional wraps a potentially-null value and forces the caller to handle the empty case
- Never use Optional.get() without isPresent() check
Source tags: optional / null-safety / java-8 / java
QUESTION 12 / easy / conceptual
What is the difference between ArrayList and LinkedList in Java?
Supplied choices
- LinkedList is always faster than ArrayList for all operations
- ArrayList uses more memory than LinkedList
- ArrayList is O(1) random access with O(n) middle inserts; LinkedList is O(n) random access with O(1) insert at known position
- They have identical performance — ArrayList is just syntactic sugar for LinkedList
Source answer choice: C. ArrayList is O(1) random access with O(n) middle inserts; LinkedList is O(n) random access with O(1) insert at known position
Sample answer
Hints to guide your next attempt
- Dynamic array vs doubly-linked list
- Random access vs insert/delete performance
Source tags: arraylist / linkedlist / collections / time-complexity / java
Check understanding, not recognition
- Can you explain the answer without reading it?
- Can you show when the approach fails or needs a different assumption?
- Can you connect the concept to a real project, task, or decision you have made?
- Can you distinguish a simplified interview example from a production requirement?
A LITTLE MORE CLARITY
Frequently asked questions
How many Java questions are shown here?
This public preview shows 12 questions with the supplied answers from the app's 50-question Java bank. Full interactive practice requires signing in.
Should I memorize the sample answers?
Use them as reference explanations, not a script or a guarantee of technical correctness for every environment. Explain your assumptions, validate code against your language and version, and discuss trade-offs. Behavioral answers should be built from your own experience.
What do hints and solution steps mean?
Hints identify ideas to consider before reading the answer. When the source question includes steps, they are shown as a separate walkthrough. Example capacities and design targets in a solution are assumptions for that exercise, not real system statistics.
BUILD YOUR NEXT OPPORTUNITY
Practice Java actively.
Sign in to use the full topic bank and interactive practice workspace.