Java Interview Question
Java Interview Question
1. What is Java?
Java is a high-level, class-based, object-oriented programming language designed to have as few
implementation dependencies as possible.
2. What are the features of Java?
Platform independent, Object-oriented, Simple, Secure, Robust, Portable, Multithreaded, High
performance.
3. What is JVM, JRE, and JDK?
o JVM: Java Virtual Machine (runs the bytecode)
o JRE: Java Runtime Environment (JVM + libraries)
o JDK: Java Development Kit (JRE + development tools)
4. What is a Class in Java?
A class is a blueprint from which objects are created.
5. What is an Object in Java?
An object is an instance of a class containing state (variables) and behavior (methods).
6. What is the difference between == and .equals()?
== compares references, .equals() compares values (can be overridden).
7. What are access modifiers in Java?
private, default, protected, public — control the visibility of classes and members.
8. What is the difference between method overloading and method overriding?
o Overloading: same method name, different parameters (within same class)
o Overriding: same method signature in subclass
9. What is inheritance in Java?
It allows one class to inherit properties and methods of another class using extends keyword.
10. What is encapsulation?
Wrapping of data (variables) and code (methods) into a single unit (class), and restricting direct
access to some of the object's components.
11. What is abstraction?
Hiding internal implementation details and showing only functionality using abstract classes or
interfaces.
12. What is polymorphism?
The ability to take many forms — method overloading and overriding are examples.
13. What is an interface?
An interface is a contract that defines a set of methods that a class must implement.
14. What is the difference between an abstract class and an interface?
• Abstract class can have method definitions; interface methods are abstract by default (Java 8+
allows default/static methods in interfaces).
• A class can implement multiple interfaces but only extend one class.
15. What is a constructor in Java?
A constructor is a special method used to initialize objects.
16. What is the default constructor?
A constructor with no parameters provided by the compiler if no other constructors are defined.
17. What is the final keyword?
Used to declare constants, prevent method overriding, and inheritance of a class.
18. What is static in Java?
Used to declare class-level variables and methods shared across all instances.
19. What is the main method in Java?
Entry point: public static void main(String[] args)
20. What is exception handling?
Mechanism to handle runtime errors using try-catch blocks.
21. What is the difference between checked and unchecked exceptions?
• Checked: Checked at compile-time (e.g., IOException)
• Unchecked: Checked at runtime (e.g., NullPointerException)
22. What is a package in Java?
A namespace to organize classes and interfaces.
23. What is the use of this keyword?
Refers to the current class instance.
24. What is the use of super keyword?
Refers to the parent class instance.
25. What is the difference between ArrayList and LinkedList?
• ArrayList: Fast for accessing elements
• LinkedList: Fast for inserting/deleting elements
26. What is garbage collection?
Automatic memory management that reclaims memory used by objects no longer referenced.
27. What are wrapper classes?
Classes that convert primitives into objects (e.g., int → Integer)
28. What is the difference between String, StringBuilder, and StringBuffer?
• String: Immutable
• StringBuilder: Mutable and faster (not thread-safe)
• StringBuffer: Mutable and thread-safe
29. What are the types of loops in Java?
for, while, do-while, and enhanced for-each loop
30. What is a thread in Java?
A thread is a lightweight subprocess — smallest unit of processing.