Top 100 Most Asked Java Interview Questions (With Answers)

Java is one of the most widely used programming languages in the world, and it’s a favorite among companies for building scalable, high-performance applications. Whether you’re a fresher or an experienced developer, preparing for Java interviews can be challenging due to the vastness of the language.

In this blog post, we’ve curated 100 most commonly asked Java interview questions, categorized topic-wise, with brief and clear answers. This guide will help you revise core concepts, brush up on practical knowledge, and build the confidence needed to crack any Java interview.

Most Asked Java Interview Questions

1. Java Basics (Core Java)

Q1. What is Java?
Java is a high-level, class-based, object-oriented programming language designed to have as few implementation dependencies as possible.

Q2. What are the main features of Java?
Platform-independent, Object-oriented, Secure, Robust, High performance, Multithreaded, Architecture-neutral.

Q3. What is JVM, JRE, and JDK?

  • JVM: Java Virtual Machine – runs Java bytecode
  • JRE: Java Runtime Environment – includes JVM + libraries
  • JDK: Java Development Kit – includes JRE + development tools

Q4. What is the difference between == and .equals()?
== compares object references; .equals() compares object content.

Q5. What are access modifiers in Java?
public, private, protected, and default – they define access level.

Q6. What is a wrapper class?
Wrapper classes convert primitives into objects (e.g., int → Integer).

Q7. What is type casting in Java?
Converting one data type into another. Two types: implicit and explicit.

Q8. What is the default value of local variables?
Local variables do not have a default value and must be initialized.

Q9. What are static variables and methods?
They belong to the class rather than instances and can be accessed without creating objects.

Q10. What is the final keyword in Java?
Used to define constants, prevent method overriding, or inheritance.


2. Object-Oriented Programming (OOP)

Q11. What are the four pillars of OOP?
Encapsulation, Inheritance, Abstraction, Polymorphism.

Q12. What is encapsulation?
Wrapping data and methods together to protect internal state.

Q13. What is inheritance?
One class acquires the properties and behaviors of another.

Q14. What is method overloading?
Defining multiple methods with the same name but different parameters.

Q15. What is method overriding?
Redefining a parent class method in a child class.

Q16. What is abstraction in Java?
Hiding implementation details and showing only essential features.

Q17. What is an interface in Java?
A reference type with only abstract methods (until Java 8).

Q18. Can we instantiate an abstract class?
No, abstract classes cannot be instantiated.

Q19. What is the difference between abstract class and interface?
Abstract class can have code; interface only declarations (until Java 8).

Q20. What is a constructor?
A special method used to initialize objects.


3. Exception Handling

Q21. What is an exception?
An exception is an event that disrupts the normal flow of the program.

Q22. Difference between checked and unchecked exceptions?
Checked: handled at compile time (IOException); Unchecked: at runtime (NullPointerException).

Q23. What is the use of try-catch block?
To handle exceptions and avoid program termination.

Q24. What is finally block?
Always executed after try-catch, used for cleanup code.

Q25. What is throw vs throws?
throw is used to explicitly throw an exception; throws declares exceptions.

Q26. Can a try block exist without a catch?
Yes, only if it has a finally block.

Q27. What is a custom exception?
User-defined exception class that extends Exception.

Q28. What happens if exception is not handled?
Program terminates and stack trace is shown.

Q29. Can we catch multiple exceptions in one catch block?
Yes, from Java 7 onwards using multi-catch syntax.

Q30. What is the difference between Error and Exception?
Error indicates serious problems (e.g., OutOfMemoryError), Exception is recoverable.


4. Java 8 Features

Q31. What is a lambda expression?
A short block of code which takes parameters and returns a value.

Q32. What is a functional interface?
An interface with a single abstract method.

Q33. What is the Stream API?
Used to process collections of data in a functional style.

Q34. What is the default method in an interface?
A method with implementation inside an interface (Java 8+).

Q35. What is Optional in Java 8?
A container object that may or may not contain a non-null value.

Q36. What is method reference?
A shorthand syntax for a lambda expression that calls a method.

Q37. What is the difference between map and flatMap?
map() transforms each element; flatMap() flattens nested structures.

Q38. What is the purpose of the forEach method?
To perform an action for each element of a collection.

Q39. What is the use of Predicate and Consumer?
Functional interfaces used in lambda expressions and streams.

Q40. Can you use Stream API with arrays?
Yes, using Arrays.stream() method.


5. Collections Framework

Q41. What is the difference between List and Set?
List allows duplicates and maintains order; Set does not allow duplicates.

Q42. What is the difference between ArrayList and LinkedList?
ArrayList is backed by array; LinkedList uses a doubly linked list.

Q43. What is HashMap?
It stores key-value pairs and does not allow duplicate keys.

Q44. What is the difference between HashMap and Hashtable?
HashMap is not synchronized; Hashtable is thread-safe.

Q45. What is TreeSet?
A NavigableSet that maintains elements in sorted order.

Q46. What is the use of Iterator?
Used to traverse collections.

Q47. What is fail-fast and fail-safe in collections?
Fail-fast throws exceptions if structure is modified during iteration; fail-safe does not.

Q48. What is the difference between Comparable and Comparator?
Comparable is used for natural ordering; Comparator for custom ordering.

Q49. How does HashMap work internally?
Uses hashCode and equals methods to store and retrieve data.

Q50. What is ConcurrentHashMap?
A thread-safe version of HashMap that allows concurrent read and write.


6. Multithreading

Q51. What is a thread in Java?
A thread is a lightweight subprocess that runs concurrently.

Q52. How to create a thread in Java?
By extending Thread class or implementing Runnable interface.

Q53. What is the difference between start() and run()?
start() starts a new thread; run() executes in current thread.

Q54. What is synchronization?
Used to control access to shared resources to avoid race conditions.

Q55. What is deadlock?
A situation where two or more threads are waiting for each other to release resources.

Q56. What is the lifecycle of a thread?
New → Runnable → Running → Blocked → Terminated.

Q57. What is the difference between sleep() and wait()?
sleep() pauses a thread for specific time; wait() releases the lock.

Q58. What is volatile keyword?
Ensures that changes made by one thread are visible to others.

Q59. What is the use of join() method?
It waits for a thread to finish its execution.

Q60. What is the Executor framework?
A high-level API to manage thread execution using thread pools.


7. Java Memory Management

Q61. What is garbage collection?
The process of automatically reclaiming memory used by unreferenced objects.

Q62. What are the different memory areas in JVM?
Heap, Stack, Method Area, Program Counter Register, Native Method Stack.

Q63. What is the difference between heap and stack memory?
Heap stores objects; stack stores method calls and local variables.

Q64. What is OutOfMemoryError?
Thrown when JVM runs out of memory.

Q65. What are strong, weak, soft, and phantom references?
Different levels of object referencing for garbage collection purposes.

Q66. What is finalization?
A mechanism to perform cleanup before object is garbage collected.

Q67. What are memory leaks in Java?
Unintended object references that prevent garbage collection.

Q68. How can you monitor memory usage in Java?
Using tools like JVisualVM, JConsole, and JVM options.

Q69. What is permgen/metaspace?
Memory area used for storing class metadata (replaced by metaspace in Java 8).

Q70. Can you force garbage collection in Java?
System.gc() can request it, but it’s not guaranteed.


8. Strings and StringBuilder

Q71. What is the difference between String, StringBuilder, and StringBuffer?
String is immutable, StringBuilder is mutable and non-thread-safe, StringBuffer is thread-safe.

Q72. Why is String immutable in Java?
To ensure security, thread safety, and caching.

Q73. What is String pool?
A memory area where string literals are stored to optimize memory usage.

Q74. How to compare two strings in Java?
Using .equals() for content and == for reference comparison.

Q75. What is the use of substring() method?
To extract part of a string.

Q76. How to convert String to int?
Using Integer.parseInt().

Q77. How to reverse a string in Java?
Using StringBuilder.reverse() or manual loop logic.

Q78. Can strings be changed in Java?
No, strings are immutable; use StringBuilder for modifications.

Q79. What is intern() method?
Used to store string in the pool if it’s not already there.

Q80. What is the time complexity of string concatenation?
O(n), especially when using + in loops; better to use StringBuilder.


9. Java Input/Output (IO)

Q81. What are the types of streams in Java IO?
Byte streams (InputStream, OutputStream) and character streams (Reader, Writer).

Q82. What is the difference between FileReader and BufferedReader?
BufferedReader is faster due to internal buffer and readLine() method.

Q83. How to read a file in Java?
Using FileReader, BufferedReader, or Files.readAllLines() in Java 8.

Q84. What is serialization?
The process of converting an object into a byte stream.

Q85. What is the purpose of transient keyword?
Prevents variables from being serialized.

Q86. What is the difference between File and FileInputStream?
File is an abstract representation; FileInputStream reads file content.

Q87. How to write to a file in Java?
Using FileWriter, BufferedWriter, or Files.write().

Q88. What is ObjectOutputStream?
Used to write serialized objects to a file or stream.

Q89. What is try-with-resources?
A feature to auto-close resources like files, streams.

Q90. How to copy a file in Java?
Using Files.copy() or manual stream logic.


10. Advanced Java Topics

Q91. What is Reflection in Java?
It allows inspecting and modifying classes, fields, and methods at runtime.

Q92. What is annotation in Java?
Metadata that provides data about the program, e.g., @Override.

Q93. What is enum in Java?
A special class representing a group of constants.

Q94. What is Java API?
A collection of prewritten packages, classes, and interfaces.

Q95. What is JDBC?
Java Database Connectivity – used to connect and interact with databases.

Q96. What is the Singleton design pattern?
Ensures only one instance of a class exists throughout the application.

Q97. What is a marker interface?
An interface with no methods, e.g., Serializable.

Q98. What is Java Reflection API used for?
To examine and modify class structures at runtime.

Q99. What is the difference between shallow copy and deep copy?
Shallow copy copies references; deep copy copies actual objects.

Q100. What is the use of volatile keyword in multithreading?
Ensures visibility of changes to variables across threads.


In The End
Preparing for a Java interview doesn’t have to be overwhelming. Focus on the fundamentals, understand core concepts, and practice coding regularly. These 100 questions cover a broad spectrum of Java topics and are highly useful for both freshers and experienced developers.

Scroll to Top