Free tutorials in Hindi & English Daily computer, mobile and IT guides Beginner friendly learning
Blog · Java · 04 Jul 2026 · Hindi + English

Top 15 Java Interview Questions for Freshers with Answers

15 most-asked core Java questions: JDK/JRE/JVM, == vs equals, String immutability, static, OOPs pillars, abstract vs interface and tricky outputs.

How to use this list

These 15 core Java questions dominate fresher interviews and campus placements. Answers are written the way you should say them — short, precise, with the trap highlighted.

Platform and basics (1–5)

Q1. What is the difference between JDK, JRE and JVM?

JVM executes bytecode; JRE = JVM + libraries (to run); JDK = JRE + compiler and tools (to develop). Follow-up trap: JVM itself is platform dependent — the bytecode is what's platform independent.

Q2. Why is Java platform independent?

Source compiles to bytecode, not machine code. The same .class file runs on any OS via that OS's JVM — "write once, run anywhere".

Q3. Why is String immutable?

String pool sharing, security (paths, URLs), thread safety, and stable hashcodes for HashMap keys. Any "change" creates a new String object.

Q4. Difference between == and equals()?

== compares references; equals() compares content when overridden. Literals may pass == due to the String pool, but runtime Strings won't — always use equals().

Q5. String vs StringBuffer vs StringBuilder?

String immutable; StringBuffer mutable + synchronized (thread-safe, slower); StringBuilder mutable, fastest — the default for string building in loops.

OOPs (6–11)

Q6. What are the 4 pillars of OOPs?

Encapsulation (data + methods bundled, private fields with getters/setters), Inheritance (extends for reuse), Polymorphism (overloading + overriding), Abstraction (hide implementation via abstract classes/interfaces). Give one example each.

Q7. Overloading vs overriding?

Overloading: same name, different parameters, same class, compile time. Overriding: identical signature, child class, runtime. Static methods cannot be overridden (only hidden).

Q8. Abstract class vs interface?

Abstract class: state + constructors + partial implementation, single inheritance. Interface: contract, multiple inheritance, no instance state; since Java 8 default/static methods can have bodies.

Q9. Why doesn't Java support multiple inheritance of classes?

The diamond problem — ambiguity when two parents define the same method. Interfaces solve it because they carry no state.

Q10. What is a constructor? What is the default constructor trap?

Special method, class name, no return type, runs with new. Java provides an invisible no-arg constructor only until you write any constructor — then it disappears.

Q11. Why is main() public static void?

public: JVM must reach it from outside; static: callable before any object exists; void: JVM expects no return value; String[] args: command-line arguments.

Keywords and tricky outputs (12–15)

Q12. final vs finally vs finalize?

final locks (variable/method/class); finally always runs after try-catch for cleanup; finalize() was a GC callback, deprecated since Java 9.

Q13. What does static mean and why can't static methods use this?

static members belong to the class with one shared copy. Static methods run without an object, so there is no this — hence "non-static variable cannot be referenced from a static context".

Q14. Predict the output:

Integer a = 127, b = 127;
Integer x = 128, y = 128;
System.out.println(a == b);
System.out.println(x == y);

true then false — Integer caches -128 to 127 (like Python's small-int cache). Beyond the range, new objects are created. Moral: compare wrappers with equals().

Q15. Predict the output:

String s = "a";
s.concat("b");
System.out.println(s);

a — not "ab"! concat() returns a NEW String (immutability); the result was discarded because it wasn't assigned. Correct: s = s.concat("b");

Last-minute revision line

If you remember only 5 things: JDK⊃JRE⊃JVM, == vs equals() (reference vs content), String immutability + pool, 4 OOPs pillars with one example each, and overloading (compile-time) vs overriding (runtime). These cover the majority of fresher Java rounds.

इस list को कैसे use करें

ये 15 core Java questions fresher interviews और campus placements में छाए रहते हैं. Answers वैसे लिखे हैं जैसे आपको बोलने चाहिए — छोटे, सटीक, trap highlighted.

Platform और basics (1–5)

Q1. JDK, JRE और JVM में अंतर?

JVM bytecode execute करता है; JRE = JVM + libraries (चलाने के लिए); JDK = JRE + compiler और tools (develop करने के लिए). Follow-up trap: JVM खुद platform dependent है — platform independent bytecode होता है.

Q2. Java platform independent क्यों है?

Source machine code में नहीं, bytecode में compile होता है. Same .class file हर OS पर उस OS के JVM से चलती है — "write once, run anywhere".

Q3. String immutable क्यों है?

String pool sharing, security (paths, URLs), thread safety, और HashMap keys के लिए stable hashcodes. कोई भी "change" नया String object बनाता है.

Q4. == और equals() में अंतर?

== references compare करता है; equals() overridden हो तो content. Literals String pool की वजह से == pass कर सकते हैं, पर runtime Strings नहीं — हमेशा equals() use करें.

Q5. String vs StringBuffer vs StringBuilder?

String immutable; StringBuffer mutable + synchronized (thread-safe, धीमा); StringBuilder mutable, सबसे तेज़ — loops में string building का default.

OOPs (6–11)

Q6. OOPs के 4 pillars क्या हैं?

Encapsulation (data + methods bundled, private fields with getters/setters), Inheritance (reuse के लिए extends), Polymorphism (overloading + overriding), Abstraction (abstract classes/interfaces से implementation छुपाना). हर एक का एक example दें.

Q7. Overloading vs overriding?

Overloading: same name, अलग parameters, same class, compile time. Overriding: identical signature, child class, runtime. Static methods override नहीं होते (सिर्फ hide).

Q8. Abstract class vs interface?

Abstract class: state + constructors + partial implementation, single inheritance. Interface: contract, multiple inheritance, कोई instance state नहीं; Java 8 से default/static methods में bodies हो सकती हैं.

Q9. Java classes की multiple inheritance support क्यों नहीं करता?

Diamond problem — दो parents same method define करें तो ambiguity. Interfaces इसे solve करते हैं क्योंकि उनमें state नहीं होती.

Q10. Constructor क्या है? Default constructor trap क्या है?

Special method, class name, no return type, new के साथ चलता है. Java invisible no-arg constructor तभी तक देता है जब तक आपने कोई constructor न लिखा हो — लिखते ही गायब.

Q11. main() public static void क्यों है?

public: JVM को बाहर से access चाहिए; static: बिना object के callable; void: JVM को कोई return value नहीं चाहिए; String[] args: command-line arguments.

Keywords और tricky outputs (12–15)

Q12. final vs finally vs finalize?

final lock करता है (variable/method/class); finally try-catch के बाद cleanup के लिए हमेशा चलता है; finalize() GC callback था, Java 9 से deprecated.

Q13. static का मतलब और static methods this क्यों नहीं use कर सकते?

static members class के हैं, एक shared copy. Static methods बिना object के चलते हैं, तो this है ही नहीं — इसीलिए "non-static variable cannot be referenced from a static context".

Q14. Output predict करें:

Integer a = 127, b = 127;
Integer x = 128, y = 128;
System.out.println(a == b);
System.out.println(x == y);

true फिर false — Integer -128 से 127 cache करता है (Python के small-int cache जैसा). Range के बाहर नए objects बनते हैं. सबक: wrappers equals() से compare करें.

Q15. Output predict करें:

String s = "a";
s.concat("b");
System.out.println(s);

a — "ab" नहीं! concat() NAYA String return करता है (immutability); result assign नहीं हुआ तो discard हो गया. सही: s = s.concat("b");

Last-minute revision line

सिर्फ 5 चीज़ें याद रखनी हों: JDK⊃JRE⊃JVM, == vs equals() (reference vs content), String immutability + pool, 4 OOPs pillars एक-एक example के साथ, और overloading (compile-time) vs overriding (runtime). ये freshers के अधिकतर Java rounds cover करते हैं.

Frequently Asked Questions

What are the most asked Java interview questions for freshers?

JDK vs JRE vs JVM, == vs equals(), String immutability, String vs StringBuilder, the 4 OOPs pillars, overloading vs overriding, abstract class vs interface, and static/final keywords.

What are the 4 pillars of OOPs in Java?

Encapsulation, Inheritance, Polymorphism and Abstraction — bundle data safely, reuse code via extends, one interface many forms, and hide implementation details.

Why does Integer 127 == 127 give true but 128 == 128 give false?

Java caches Integer objects from -128 to 127, so both variables share one cached object; beyond the range new objects are created and == compares references.