Free tutorials & notes in Hindi & English · Clean code examples 🧰 Free PDF & Image Tools →
🔴 Advanced  ·  Lesson 25

Java Interview Questions and Answers

In this lesson: Most-asked Core Java interview questions for freshers — OOP, JVM, strings, collections, exceptions — short answers. Prepare fast.

How to use this list

These are the questions that come up most often in Java interviews for freshers. Understand the idea behind each, and be ready to give a short, clear answer with a one-line example. Knowing why matters far more to interviewers than memorising.

💡 Tip: for each answer, give the "why" plus a tiny example. That separates a strong answer from a memorised one.

Basics and OOP

Q1. What is Java? A platform-independent, object-oriented language; code compiles to bytecode that runs on the JVM.

Q2. JDK vs JRE vs JVM? JVM runs bytecode; JRE = JVM + libraries; JDK = JRE + compiler tools.

Q3. What are the four OOP pillars? Encapsulation, inheritance, polymorphism, abstraction.

Q4. Overloading vs overriding? Overloading = same name, different parameters (compile time); overriding = child redefines a parent method (runtime).

Q5. Abstract class vs interface? Abstract has code and is extended (one); interface is a contract and can be implemented many.

Strings and types

Q6. == vs equals()? == compares references; equals() compares content.

Q7. Why are strings immutable? For safety, caching in the string pool, and predictable behaviour.

Q8. String vs StringBuilder? String is immutable; StringBuilder is mutable and fast for building text.

Q9. What is autoboxing? Java automatically converting a primitive (int) to its wrapper (Integer) and back.

Q10. final keyword? Makes a variable constant, a method non-overridable, or a class non-extendable.

Collections

Q11. List vs Set vs Map? List keeps order and duplicates; Set stores unique items; Map stores key-value pairs.

Q12. ArrayList vs LinkedList? ArrayList = fast index access; LinkedList = fast middle insert/remove.

Q13. HashMap vs Hashtable? HashMap is fast and not thread-safe; Hashtable is thread-safe but slower and legacy.

Q14. HashSet vs TreeSet? HashSet has no order and is fast; TreeSet keeps items sorted.

Q15. Comparable vs Comparator? Comparable is one natural order (compareTo); Comparator gives custom orders (compare).

Exceptions and more

Q16. Checked vs unchecked exceptions? Checked must be caught or declared; unchecked (RuntimeException) need not be.

Q17. final vs finally vs finalize? final = keyword; finally = block that always runs; finalize = deprecated method.

Q18. What is a thread? A separate path of execution; multithreading runs several at once.

Q19. What is the Singleton pattern? A class with only one object, via a private constructor and getInstance().

Q20. What is garbage collection? Java automatically freeing memory of objects no longer referenced.

Interview tips

  • Explain the why. Say not just what a feature does, but when and why to use it.
  • Give a one-line example. A tiny snippet shows real understanding.
  • Mention OOP and collections. They are the core of most Java interviews.
  • Be honest. If unsure, say how you would find out — that is a good sign too.

Summary

  • Know the core comparisons: == vs equals(), overloading vs overriding.
  • Explain the four OOP pillars clearly with examples.
  • Be comfortable with collections: List, Set, Map and their classes.
  • Understand exceptions, threads, Singleton and garbage collection.
  • Answer with the "why" plus a short example, not just definitions.

Revise the topics in inheritance and collections before your interview.

Frequently Asked Questions

What is the difference between == and equals() in Java?
== compares references (whether two variables point to the same object), while equals() compares the actual content. For strings and objects, use equals() to compare values.
What is the difference between an abstract class and an interface?
An abstract class can have fields and normal methods and is extended (one only). An interface is mostly method contracts and is implemented, and a class can implement many interfaces. Use abstract for shared code, interfaces for capabilities.
What is the difference between overloading and overriding?
Overloading is same method name with different parameters in one class (compile time). Overriding is a child class redefining a parent method with the same signature (runtime). One is variety; the other is replacement.
Why are strings immutable in Java?
Immutable strings are safe to share, can be cached in a string pool, and cannot be changed unexpectedly. Methods like toUpperCase() return a new String instead of changing the original.
What is the difference between ArrayList and LinkedList?
ArrayList uses an array for fast index access; LinkedList uses nodes for fast insertion and removal in the middle. Use ArrayList for reading, LinkedList for frequent middle changes.
← Back to Java Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

Next topic50 Java Practice Programs Your progress: 25 / 61 (41%) · Lesson 26 / 61 Continue →

How was this lesson?

Your feedback helps us make the content better.

Write a review or suggestion (optional)

After approval, your name and city may appear publicly with your review. Please do not write your email or phone number.

▶ CodingEasily on YouTube

Learn with video lessons in easy Hindi

Featured video: RDBMS Part 3 – Class XI Commerce IT

▶ Subscribe – it’s free