CORE JAVA
CORE JAVA
REAL-TIME
REAL-TIME
SCENARIO-BASED
SCENARIO-BASED
INTERVIEW
INTERVIEW
QUESTIONS
QUESTIONS
3- 5 YEARS OF EXPERIENCE
3- 5 YEARS OF EXPERIENCE
2025
2025
www.prominentacademy.in
+91 98604 38743
Question: You’re iterating over a list and removing elements
inside a for-each loop, and it throws
ConcurrentModificationException. Why?
Answer:
The for-each loop uses an iterator internally.
Structural modification (add/remove) breaks iterator
consistency.
Fix:
Use iterator’s remove() method
Java
Iterator<String> it = list.iterator();
while (it.hasNext()) {
if (condition) {
it.next();
it.remove();
}
}
Question:
You use a 3rd-party JAR, but it fails with
ClassNotFoundException. The class is present in the JAR.
Why?
Answer:
Might be loaded by a different classloader (like
AppClassLoader vs Bootstrap).
Check:
JAR is in correct classpath.
No version conflict.
Not loaded by custom classloader (OSGi, Tomcat, etc.)
Your next opportunity is closer than you think. Let’s get you there!
📞 Don’t wait—call us at +91 98604 38743 today
Question: You used Optional.get() and it throws
NoSuchElementException. What did you do wrong?
Answer:
You should check presence before calling .get().
Correct Way:
Java
Optional<User> userOpt = findUser();
userOpt.ifPresent(user -> System.out.println(user.getName()));
Or use orElse(), orElseThrow(), map().
Question:
Explain the order of execution between static block, instance
block, constructor, and main().
Answer:
Order:
1. Static block (only once)
2. Instance block (every time object is created)
3. Constructor
4. main() (after static block)
Your next opportunity is closer than you think. Let’s get you there!
📞 Don’t wait—call us at +91 98604 38743 today
Question: You implemented a lazy singleton using if (instance
== null) inside getInstance(), but it occasionally returns
multiple instances. Why?
Answer:
This is due to race conditions — multiple threads entering
if before instance is assigned.
Fix – Double-Checked Locking:
Java
public class Singleton {
private static volatile Singleton instance;
public static Singleton getInstance() {
if (instance == null) {
synchronized (Singleton.class) {
if (instance == null)
instance = new Singleton();
}
}
return instance;
}
}
Your next opportunity is closer than you think. Let’s get you there!
📞 Don’t wait—call us at +91 98604 38743 today
Question: You used synchronized but need more flexibility like
timeout or fairness. What’s the alternative?
Answer:
Use ReentrantLock:
Java
Lock lock = new ReentrantLock(true); // true for fairness
if (lock.tryLock(1, TimeUnit.SECONDS)) {
try {
// critical section
} finally {
lock.unlock();
}
}
Your next opportunity is closer than you think. Let’s get you there!
📞 Don’t wait—call us at +91 98604 38743 today
Question:
App is slowing down. You suspect memory leaks. How do you
find them?
Answer:
Use jvisualvm, jconsole, or heap dump analyzers like
Eclipse MAT.
Look for:
Objects with large retained size
Collections that grow but don’t shrink
Listeners not getting GC’ed
Question:
You used .stream() twice on the same stream variable and it
throws IllegalStateException. Why?
Answer:
Java streams are consumable only once.
Fix:
Use a supplier if reuse is needed:
Java
Supplier<Stream<String>> streamSupplier = () -> list.stream();
streamSupplier.get().filter(...);
streamSupplier.get().map(...);
Your next opportunity is closer than you think. Let’s get you there!
📞 Don’t wait—call us at +91 98604 38743 today
Question:
You use .parallelStream() on a shared ArrayList. Sometimes
you get ConcurrentModificationException. Why?
Answer:
ArrayList is not thread-safe.
While parallel streams use multiple threads, underlying
collection should be immutable or thread-safe.
Fix:
Use Collections.synchronizedList(...), or
Use concurrent-friendly collection, or
Avoid modifying list during parallel stream processing.
Question:
You’re using a HashMap in a multi-threaded context and
sometimes it gets into infinite loops or returns corrupted
data. Why?
Answer:
HashMap is not synchronized.
Multi-threaded writes during rehashing can cause a
cyclic linked list, leading to infinite loops.
Fix:
Use ConcurrentHashMap instead.
Your next opportunity is closer than you think. Let’s get you there!
📞 Don’t wait—call us at +91 98604 38743 today
Question:
You submitted tasks to ExecutorService but not all tasks
execute. What could be the cause?
Answer:
Pool size too small.
Queue capacity full.
Task throws exception and terminates.
ExecutorService shut down early.
Debug Tip: Use ThreadPoolExecutor with a custom
RejectedExecutionHandler.
Question:
You used ThreadLocal in a web app. After user logs out,
memory usage keeps growing. Why?
Answer:
Threads (like in thread pools) live beyond requests.
If you forget to call remove(), the value stays in memory.
Fix:
Always clean up:
java
threadLocal.remove();
Your next opportunity is closer than you think. Let’s get you there!
📞 Don’t wait—call us at +91 98604 38743 today
Think your skills are enough?
Think again—these Java
questions could cost you your
Java Developer job.
Looking to crack your java interviews and land your
dream job? 💼We've got you covered! At Prominent
Academy, we specialize in providing end-to-end
interview preparation that ensures you're not just
ready—but confident! 💪
💡 What We Cover:
✅ Mock Interviews tailored to Java developer roles
✅ Real-world scenario-based questions
✅ Guidance on resume building and LinkedIn
optimization
✅ In-depth coverage of devops core concepts and
projects
✅ Unlimited interview calls with top companies
🎯 Whether you're a fresher or an experienced professional
transitioning to java developer, we provide personalized
guidance to help you shine in interviews and stand out in the
competitive market
📞call us at +91 98604 38743 to learn more.