Core Java Interview Questions & Practical Preparation Guide

Go beyond textbook definitions with 10 uncommon, scenario-based Core Java interview questions frequently asked to filter real practitioners. At Urbancode Edutech, we train learners for interviews practically—through live debugging labs, project walkthroughs, and 1-on-1 mock panels in Velachery, Pallikaranai, Tirunelveli, and live online.

Explore Core Java Course

Practical Interview Readiness

How Urbancode Trains You Practically for Core Java Interviews

Technical panels rarely reject candidates over basic definitions—they test edge cases, production mistakes, and how you diagnose real issues. Every Core Java batch integrates practical interview preparation into hands-on training.

01

Live Debugging & Trap Scenarios

Trainers walk through edge-case failures, optimization pitfalls, and live troubleshooting instead of slide-only theory.

02

Real Project Architecture Reviews

Learn to explain design trade-offs, performance metrics, and real project workflows confidently to senior interviewers.

03

1-on-1 Mock Technical & HR Panels

Practise technical and behavioral interviews in Tamil & English with actionable feedback on technical depth and clarity.

04

Resume, Portfolio & Recruiter Prep

Align your GitHub/capstone portfolio, ATS resume keywords, and interview storytelling with hiring manager expectations.

Real Scenario Questions

Top 10 Core Java Interview Questions & Detailed Answers

Review each edge-case scenario carefully and practise explaining the root cause and fix in your own words during mock interviews.

Q1

Why does Integer a = 127; Integer b = 127; a == b return true, while 128 == 128 returns false?

Java caches boxed Integer objects in IntegerCache for values -128 to 127 by default. Thus 127 reuses the same cached reference, whereas 128 autoboxes two distinct heap objects, making == compare references instead of numeric values.

Q2

Why can modifying an object's field after inserting it into a HashSet make the element impossible to remove or find?

HashSet stores entries in buckets indexed by hashCode() at insertion time. Mutating a field included in hashCode() changes the runtime hash, so future contains() or remove() calls check the wrong bucket while the object stays orphaned in the old bucket—causing a subtle memory leak.

Q3

What happens if a finally block executes a return statement while an exception was thrown inside try?

A return inside finally silently suppresses and discards both the try return value and any unhandled exception thrown inside try or catch—making debugging nearly impossible. Never put return statements inside finally.

Q4

Why is String safe for HashMap keys and multithreading without synchronization, while StringBuilder is not?

String is immutable with a final backing byte/char array and caches its hashCode() once computed. Because no thread can mutate its contents after creation, references can be shared safely without locks and bucket hashes never drift.

Q5

What is the subtle trap with Arrays.asList(intArray) when passing a primitive int[]?

Arrays.asList expects T.... Because primitives cannot bind to generics, Java treats the entire int[] array as a single element (List<int[]>) of size 1 instead of List<Integer>. Box the array (Integer[]) or use Arrays.stream(intArray).boxed().toList().

Q6

Why does ConcurrentModificationException sometimes NOT trigger when removing the second-to-last element of an ArrayList in a for-each loop?

The ArrayList iterator checks hasNext() (cursor != size) before calling next(). Removing the second-to-last element shifts size down to match cursor, so hasNext() returns false and the loop exits cleanly without reaching checkForComodification()—hiding an intermittent bug.

Q7

How can a Java enum singleton still be broken if you aren't careful—and why is it safer against Reflection/Serialization than double-checked locking?

Unlike class-based singletons, the JVM blocks Constructor.newInstance() on enum types against reflection attacks and handles enum serialization by name identity without invoking readResolve(). Using an enum is the cleanest singleton pattern in Java.

Q8

What happens to the Java heap if a static ThreadLocal is used inside a servlet thread pool without calling .remove()?

Each worker thread holds a ThreadLocalMap whose entries use WeakReference keys, NOT weak values. While pooled threads live indefinitely, values remain strongly reachable even after the request ends—causing severe classloader/heap memory leaks.

Q9

Why does method overloading resolve at compile time while method overriding resolves at runtime?

Overload selection depends on the declared reference types of arguments (javac embeds the exact method descriptor in bytecode). Overriding (invokevirtual) inspects the actual runtime object class in the JVM vtable when executing.

Q10

Why can try-with-resources still report suppressed exceptions you wouldn't see with a plain try/finally?

If both the try body and close() throw exceptions, try-with-resources preserves the primary try exception and attaches the close() exception via Throwable.addSuppressed(), readable with getSuppressed(), whereas a manual finally close overwrites and hides the original root failure.

Practise Core Java With Live Mentors & Mock Interviews

Attend a free demo session in Velachery, Pallikaranai, Tirunelveli or live online. Review the complete Core Java course curriculum or browse related programs in Chennai.