Core Java Interview Questions and Answers
What is OOPS?
OOPS stands for Object-Oriented Programming System, which is based on the concept of objects
and classes. It focuses on principles like Encapsulation, Inheritance, Polymorphism, and
Abstraction.
What is the difference between 'throw' and 'throws' in Java?
'throw' is used to actually throw an exception, while 'throws' is used in a method signature to declare
that the method might throw an exception.
What are the four pillars of OOPS?
The four pillars of OOPS are Encapsulation, Inheritance, Polymorphism, and Abstraction.
What is the difference between '== ' and '.equals()' in Java?
'==' is used to compare memory addresses (references), while '.equals()' is used to compare the
contents of objects.
What is Autoboxing in Java?
Autoboxing is the automatic conversion of a primitive type into its corresponding wrapper class
object, like converting int to Integer.
What is the use of the 'hashCode()' method?
The 'hashCode()' method returns a hash code that helps identify an object in hash-based collections
like HashSet and HashMap.
What is the difference between ArrayList and LinkedList?
ArrayList is backed by a dynamic array, while LinkedList is backed by a doubly linked list. ArrayList
is better for random access, and LinkedList is better for frequent insertions and deletions.
What is the purpose of the 'final' keyword?
The 'final' keyword can be applied to variables (to make them constant), methods (to prevent
overriding), and classes (to prevent inheritance).
What is the use of the 'transient' keyword?
The 'transient' keyword is used to indicate that a variable should not be serialized during the
serialization process.
What is the difference between 'String', 'StringBuilder', and 'StringBuffer'?
String is immutable, StringBuilder and StringBuffer are mutable. StringBuffer is thread-safe, while
StringBuilder is not.
What is the difference between 'checked' and 'unchecked' exceptions?
Checked exceptions are those that must be either caught or declared in the method signature, while
unchecked exceptions do not require explicit handling.