Core Java Interview Questions & Answers
Sections aligned with popular Java interview guides (freshers → full stack + MCQ), written in our own words and laid out in InterviewForge AI’s emerald “study grid” UI.
Work through **Java for freshers**, **intermediate** core APIs, **experienced-level** JVM and concurrency, **coding problems**, **tricky** behaviors, **scenarios**, **memory**, **Java 11**, **full-stack Java**, then **MCQs**. Expand any card for a tight interview answer. Optional code samples appear where they help more than prose.
1Java Interview Questions for Freshers
Platform basics, memory model at a high level, OOP, constructors, exceptions, static, and GC fundamentals.
Language & platform
▸Why is Java described as platform independent?
▸Why is Java not considered a “pure” object-oriented language?
▸What is the difference between stack and heap memory in Java?
▸How does Java differ from C++ at a high level?
▸Why doesn’t Java expose pointers like C or C++?
OOP, variables, and control flow
▸What is the difference between an instance variable and a local variable?
▸What default values do instance and class fields get?
▸What is encapsulation?
▸What does a JIT compiler do in the JVM?
▸Compare `==` and `.equals()` for reference types.
Methods, exceptions, static, GC basics
▸How do you write an intentional infinite loop in Java?
▸What is constructor overloading?
▸Can the `main` method be overloaded?
▸Why is `main` static?
▸Can static methods be overridden?
▸Can one `try` have multiple `catch` blocks?
▸What does `final` mean on variables, methods, and classes?
▸When might `finally` not run?
2Java Intermediate Interview Questions
Strings beyond basics, singleton patterns, collections, threading introductions, reflection trade-offs, and API comparisons.
Strings, builders, and core APIs
▸Besides security, why are strings immutable in Java?
▸What is a singleton and a simple safe pattern?
▸`String` vs `StringBuilder` vs `StringBuffer`?
▸Interfaces vs abstract classes (modern Java)?
▸`HashMap` vs `Hashtable`?
Threads, reflection, pass-by-value
▸Two common ways to create a thread?
▸Why is reflection both powerful and risky?
▸Does Java pass by reference or value?
▸Why might `char[]` be preferred over `String` for secrets?
3Java Interview Questions for Experienced
Composition vs inheritance, advanced operators, synchronization, varargs, UTF-16 quirks, and framework-aware answers.
Design & runtime
▸Why is composition often favored over inheritance?
▸Difference between `>>` and `>>>`?
▸`new` vs reflective `Constructor.newInstance` / older `Class.newInstance` patterns?
▸Why is synchronization needed?
▸What does `String... args` mean?
Ecosystem (Spring touchpoints)
▸Name common Spring bean scopes.
4Java Programming Interview Questions
Short coding-style prompts with reference implementations you can rehearse aloud or type in our online practice flow.
Recursion & arrays
▸Check if a string is a palindrome using recursion.
static boolean isPalindrome(String s, int lo, int hi) {
if (lo >= hi) return true;
if (s.charAt(lo) != s.charAt(hi)) return false;
return isPalindrome(s, lo + 1, hi - 1);
}▸Print Fibonacci numbers with a simple recursive helper.
static void fib(int a, int b, int left) {
if (left == 0) return;
int c = a + b;
System.out.print(c + " ");
fib(b, c, left - 1);
}▸Find one missing number from 1..n in an unsorted array of unique ints.
static int missing(int[] a) {
int n = a.length + 1;
long expected = (long) n * (n + 1) / 2;
long sum = 0;
for (int v : a) sum += v;
return (int) (expected - sum);
}Strings & search
▸Test if two strings are anagrams (Ascii, case-sensitive variant).
static boolean isAnagram(String a, String b) {
if (a.length() != b.length()) return false;
int[] c = new int[256];
for (int i = 0; i < a.length(); i++) {
c[a.charAt(i)]++;
c[b.charAt(i)]--;
}
for (int v : c) if (v != 0) return false;
return true;
}▸Recursive binary search returning boolean.
static boolean binSearch(int[] a, int key, int lo, int hi) {
if (lo > hi) return false;
int mid = lo + (hi - lo) / 2;
if (a[mid] == key) return true;
if (key < a[mid]) return binSearch(a, key, lo, mid - 1);
return binSearch(a, key, mid + 1, hi);
}5Tricky Java Interview Questions
Edge cases that trip panelists: immutability pitfalls, `finally` returns, char arithmetic, overload ambiguity.
Puzzles
▸Why can `s += "b"` on a String create extra objects?
▸Why does `System.out.println('a' + 'b');` print a number?
▸If both `try` and `finally` return a value, which wins?
▸Why is removing index `0` from `ArrayList` expensive?
6Scenario-Based Java Interview Questions
Production thinking: latency, OOM, idempotency, concurrency, and observability.
What interviewers ask when they want judgment
▸The service slows down after several hours. What do you check first?
▸You hit `OutOfMemoryError: Java heap space`. Name three realistic causes.
▸A background job sometimes runs twice. How do you keep outcomes safe?
7Java Memory Management Interview Questions
Heap vs stack recap, reachability, leaks, references, and GC intuition.
Quick hits
▸What is garbage collection’s main goal?
▸When is an object eligible for GC?
▸What does a memory leak mean in Java?
8Java 11 Interview Questions
LTS rationale, `var`, HTTP client, string helpers, and migration notes.
Java 11 topics
▸Why do enterprises standardize on Java 11 LTS?
▸What is `var` and where can it appear?
▸What did `java.net.http.HttpClient` change for developers?
9Java Full Stack Developer Interview Questions
REST shape, auth vs authz, transactions, ORM pitfalls, and deployment.
Backend + web concerns
▸How do you sketch a REST API in Spring Boot at a high level?
▸Authentication vs authorization?
▸What is the N+1 query problem in JPA/Hibernate?
10Conclusion
How to use this guide with InterviewForge AI mock interviews and ATS prep.
Next steps
▸How should you combine reading with practice?
11Java MCQ (sample)
Rapid checks similar to end-of-guide quizzes on large interview sites.
Practice set
Which component typically performs JIT compilation of hot bytecode?
- A.JDK
- B.JVM
- C.JRE only
- D.`javac` only
`String a = new String("x"); String b = "x";` What does `a == b` evaluate to?
- A.true
- B.false
- C.Compilation error
- D.Undefined
During many stop-the-world GC events, application threads are typically:
- A.Always running unaffected
- B.Paused
- C.Duplicated
- D.Run in reverse order
Which collection allows one `null` key in typical `HashMap` semantics?
- A.`Hashtable`
- B.`TreeMap` always
- C.`HashMap`
- D.`ConcurrentSkipListMap`
If a method declares `throws IOException`, callers must:
- A.Ignore it
- B.Catch or declare
- C.Mark method native
- D.Use varargs
Composition (strong ownership) vs aggregation is mainly about:
- A.Keyword `static`
- B.Lifecycle coupling of parts
- C.`equals` hashing
- D.String pool usage