Java Interview Questions and Answers
Java is a widely used programming language that has been around for over two decades. It is used in many industries, including finance, healthcare, and gaming, among others.
If you’re looking to land a job as a Java developer, you’ll need to be well-prepared for the interview process.
To help you prepare, we have compiled a list of the most commonly asked Java interview questions and answers. This PDF contains 100 Q&A that cover topics such as Java basics, object-oriented programming, collections, multithreading, exception handling, and more.
Java Interview Questions PDF
By studying these questions and answers, you’ll be well-equipped to tackle any Java interview with confidence. So, let’s dive in and start preparing for your next Java interview!












The Contents
- What is Java?
- What is the difference between Java and JavaScript?
- What is the main principle of Java programming?
- What are the main features of Java?
- What is a class in Java?
- What is an object in Java?
- What is a method in Java?
- What is the difference between a class and an object?
- What is inheritance in Java?
- What are the types of inheritance in Java?
- What is polymorphism in Java?
- What are the access modifiers in Java?
- What is encapsulation in Java?
- What is a constructor in Java?
- What is the difference between a constructor and a method?
- What is the Java Virtual Machine (JVM)?
- What is the Java Development Kit (JDK)?
- What is the difference between the JDK and the JRE?
- What is a package in Java?
- What is the difference between an abstract class and an interface?
- What is a static method in Java?
- What is the keyword “final” used for in Java?
- What is method overloading in Java?
- What is method overriding in Java?
- What is the difference between method overloading and method overriding?
- What is the “this” keyword in Java?
- What is a static variable in Java?
- What is the purpose of the “final” keyword in method parameters?
- What is the purpose of the “static” keyword in Java?
- What is the difference between “==” and “.equals()” in Java?
- What is the purpose of the “super” keyword in Java?
- What is a thread in Java?
- How do you create and start a thread in Java?
- What is synchronization in Java?
- What is the difference between the “synchronized” block and the “synchronized” method?
- What is the purpose of the “volatile” keyword in Java?
- What is an exception in Java?
- What is the difference between checked and unchecked exceptions?
- How do you handle exceptions in Java?
- What is the purpose of the “finally” block in exception handling?
- What is the difference between the “throw” and “throws” keywords in Java?
- What is the difference between checked exceptions and runtime exceptions?
- What is the Java API?
- What is the difference between an ArrayList and a LinkedList?
- What is the difference between a HashSet and a TreeSet?
- What is the difference between the “equals()” method and the “hashCode()” method?
- What is the difference between a shallow copy and a deep copy?
- What is a lambda expression in Java?
- What is functional programming in Java?
- What are the Java 8 features for functional programming?
- What is the difference between an interface and an abstract class?
- What is the purpose of the “default” keyword in interface methods?
- What is the difference between a BufferedReader and a Scanner?
- What is the purpose of the “StringBuilder” class in Java?
- What is the difference between the “Comparable” and “Comparator” interfaces?
- What is the purpose of the “assert” keyword in Java?
- What is the difference between a local variable and an instance variable?
- What is the purpose of the “transient” keyword in Java?
- What is the purpose of the “static” block in Java?
- What is the purpose of the “strictfp” keyword in Java?
- What is the difference between a public class and a default (package-private) class?
- What is the purpose of the “enum” keyword in Java?
- What is the purpose of the “break” and “continue” statements in Java?
- What is the purpose of the “try-with-resources” statement in Java?
- What is the purpose of the “instanceof” operator in Java?
- What is the difference between the pre-increment and post-increment operators?
- What is the difference between the pre-decrement and post-decrement operators?
- What is the purpose of the “Math” class in Java?
- What is the purpose of the “StringBuffer” class in Java?
- What is the purpose of the “Math.random()” method in Java?
- What is the purpose of the “Character” class in Java?
- What is the purpose of the “Integer” class in Java?
- What is the purpose of the “Double” class in Java?
- What is the purpose of the “System” class in Java?
- What is the purpose of the “File” class in Java?
- What is the purpose of the “FileNotFoundException” in Java?
- What is the purpose of the “NullPointerException” in Java?
- What is the purpose of the “ArrayIndexOutOfBoundsException” in Java?
- What is the purpose of the “ArithmeticException” in Java?
- What is the purpose of the “NumberFormatException” in Java?
- What is the purpose of the “StringBuilder” class in Java?
- What is the purpose of the “HashSet” class in Java?
- What is the purpose of the “HashMap” class in Java?
- What is the purpose of the “LinkedList” class in Java?
- What is the purpose of the “Comparator” interface in Java?
- What is the purpose of the “Comparable” interface in Java?
- What is the purpose of the “super” keyword in Java?
- What is the purpose of the “this” keyword in Java?
- What is the purpose of the “final” keyword in Java?
- What is the purpose of the “static” keyword in Java?
- What is the purpose of the “abstract” keyword in Java?
- What is the purpose of the “interface” keyword in Java?
- What is the purpose of the “package” keyword in Java?
- What is the purpose of the “import” keyword in Java?
- What is the purpose of the “throw” keyword in Java?
- What is the purpose of the “throws” keyword in Java?
- What is the purpose of the “try-catch-finally” block in Java?
- What is the purpose of the “instanceof” operator in Java?
- What is the purpose of the “break” statement in Java?
- What is the purpose of the “continue” statement in Java?
Topics Covered in the 100 Questions
| Topic | Questions |
|---|---|
| Java basics, JVM, JDK and JRE | 1–4, 16–19, 43 |
| OOP: classes, objects, inheritance, polymorphism, encapsulation | 5–15, 20, 23–25, 51, 91–92 |
| Keywords: static, final, this, super, transient, volatile and more | 21–22, 26–31, 36, 56, 58–60, 62, 87–90, 93–94 |
| Multithreading and synchronization | 32–36 |
| Exception handling | 37–42, 64, 76–80, 95–97 |
| Collections and comparison: ArrayList, LinkedList, HashSet, HashMap, Comparable | 44–46, 55, 82–86 |
| Java 8: lambdas, functional programming, default methods | 48–50, 52 |
| Strings and core classes (StringBuilder, Math, wrappers, System, File) | 30, 54, 68–75, 81 |
Sample Answers to 8 of the Most Asked Questions
Here is how to answer some of the most frequent questions from the list clearly and briefly, the way interviewers like to hear them.
1. What is the difference between JDK, JRE and JVM?
The JVM runs Java bytecode. The JRE is the JVM plus the core libraries needed to run applications. The JDK is the JRE plus development tools such as the compiler (javac) and debugger. You need the JDK to write code and the JRE to run it.
2. What is the difference between == and .equals()?
== compares references (whether two variables point to the same object). .equals() compares content, as defined by the class.
String a = new String("java");
String b = new String("java");
System.out.println(a == b); // false: different objects
System.out.println(a.equals(b)); // true: same content3. Method overloading vs. method overriding?
Overloading means the same method name with different parameters in the same class, resolved at compile time. Overriding means a subclass provides its own implementation of a parent method with the same signature, resolved at runtime (runtime polymorphism).
4. Abstract class vs. interface?
An abstract class can have state (fields), constructors and both abstract and concrete methods, and a class can extend only one. An interface defines a contract; since Java 8 it can have default and static methods, and a class can implement many interfaces. Use an interface for a capability (“can do”) and an abstract class for a shared base (“is a”).
5. ArrayList vs. LinkedList?
ArrayList is backed by a dynamic array: fast random access by index, slower inserts and removals in the middle. LinkedList is a doubly linked list: fast inserts and removals at the ends, slow access by index. In practice, ArrayList is the default choice.
6. Checked vs. unchecked exceptions?
Checked exceptions (such as IOException) must be caught or declared with throws, and the compiler enforces this. Unchecked exceptions extend RuntimeException (such as NullPointerException) and usually indicate programming errors.
7. String vs. StringBuilder vs. StringBuffer?
String is immutable, so every change creates a new object. StringBuilder is mutable and fast, and is the right choice for building strings in a loop. StringBuffer is also mutable but synchronized (thread-safe), which makes it slower.
8. What do synchronized and volatile do?
synchronized lets only one thread at a time run a block or method on the same lock, which gives both mutual exclusion and visibility. volatile only guarantees that changes to a variable are immediately visible to other threads; it does not make compound operations like count++ atomic.
How to Prepare with This PDF
- Answer out loud first, then check the PDF. Interviews test how clearly you explain, not only what you know.
- Write a small code example for each concept (overriding, exceptions, collections). Many interviewers ask you to code it on the spot.
- Group the questions by topic using the table above and study one topic per day.
- Practice coding problems too, with LeetCode Solutions in Java.
Frequently Asked Questions
Is this PDF suitable for freshers?
Yes. Most of the 100 questions cover core Java and OOP fundamentals, which are exactly what fresher and junior interviews focus on. Experienced candidates can use it as a quick revision.
Which Java topics are asked most in interviews?
OOP principles, the String class, collections (especially HashMap and ArrayList), exception handling, multithreading basics and Java 8 features such as lambdas and streams.
Number of Pages
13 Pages
To Download PDF
Related Free Java Resources
- Technical Java Questions for Automation Testers PDF
- Top 100 Java Questions and Answers PDF
- Top 50 Java Interview Questions and Answers PDF
- 150+ Java Interview Questions (Basic, Intermediate & Advanced)
- Java Programming PDF
- 50+ Java Coding Questions Every Developer Should Practice




