Java Interview Questions and Answers
1. What is Java?
Java is a high-level, class-based, object-oriented programming language developed by Sun
Microsystems, now owned by Oracle. It is platform-independent due to the Java Virtual Machine
(JVM).
2. Explain the difference between JDK, JRE, and JVM.
JDK (Java Development Kit) is a software development environment used to develop Java
applications. JRE (Java Runtime Environment) provides libraries and resources for running Java
applications. JVM (Java Virtual Machine) is an abstract machine that enables the execution of Java
bytecode.
3. What are the main features of Java?
Some key features of Java include Object-Oriented, Platform-Independent, Robust, Secure,
Multithreaded, and High Performance.
4. Explain the concept of Object-Oriented Programming in Java.
Object-Oriented Programming (OOP) is a paradigm that uses objects and classes. The four main
principles are Encapsulation, Abstraction, Inheritance, and Polymorphism.
5. What is the difference between an abstract class and an interface?
An abstract class can have both abstract (without body) and concrete (with body) methods, while an
interface can only have abstract methods (until Java 8 which introduced default and static methods).
Interfaces support multiple inheritance, while abstract classes do not.
6. What is a constructor in Java?
A constructor is a special method that initializes a newly created object. It has the same name as the
class and does not have a return type.
7. Explain the 'this' keyword in Java.
The 'this' keyword refers to the current object. It is used to resolve naming conflicts, invoke current
class constructors, or pass the current object as a parameter.
8. What is the difference between == and .equals() in Java?
The '==' operator compares object references, whereas the .equals() method compares the actual
contents of objects.
9. Explain the concept of Garbage Collection in Java.
Garbage Collection is the process of automatically reclaiming memory occupied by unused objects.
The JVM's Garbage Collector handles this process to ensure efficient memory management.
10. What is Exception Handling in Java?
Exception Handling is a mechanism to handle runtime errors. Java uses try, catch, and finally blocks
to manage exceptions and prevent program crashes.