A class defines both data (fields) and behavior (methods), and can have full method implementations.
An interface defines only method signatures, not implementations, serving as a contract.
A class can extend one class but implement multiple interfaces, allowing abstraction.
Interfaces enable multiple inheritance and polymorphic behavior in Java.
Example: class Dog implements Animal means Dog follows Animalβs contract.
An abstract class is a base class that cannot be instantiated directly.
It can have both abstract (unimplemented) and concrete (implemented) methods.
Abstract classes allow partial implementation for subclasses to reuse.
Example: abstract class Shape { abstract void draw(); }
Concrete classes like Circle or Square must implement draw().
Java exception handling uses five main keywords: try, catch, finally, throw, and throws.
The try block contains risky code, and catch handles exceptions.
finally always executes, used for cleanup operations.
throw manually raises exceptions, while throws declares possible exceptions.
Together they ensure smooth error handling and prevent abnormal termination.
Deadlock occurs when two or more threads hold resources and wait endlessly for each other.
It happens due to improper synchronization and lock ordering.
Race Condition arises when multiple threads modify shared data concurrently.
It causes inconsistent or unexpected results during execution.
Using synchronized blocks and thread-safe designs helps avoid both issues.
The equals() method compares the contents of two strings instead of references.
Example: "Java".equals("Java") returns true.
The regionMatches() method compares a specific part (region) of two strings.
Example: str1.regionMatches(0, str2, 0, 3) compares first three characters.
Both methods belong to the String class and help in text comparison.