java.lang
Class Exception
java.lang.Object
↳ java.lang.Throwable
↳ java.lang.Exception
All Implemented Interfaces:
Serializable
1.java.lang
This is the package name.
Exception class belongs to the java.lang package.
- Class Exception Exception is a class It is used for handling exceptions. Example:
catch(Exception e)
Here Exception is a class object type.
- java.lang.Object This is the topmost parent class in Java. Every class in Java indirectly inherits from Object.
Example
class Student {
}
Internally Java treats it as:
class Student extends Object {
}
Object class provides methods like:
toString()
equals()
hashCode()
- java.lang.Throwable Throwable is the parent class for: Exceptions Errors
Hierarchy:
Object
↓
Throwable
↓
Exception
Why Throwable?
Because only objects derived from Throwable can be:
thrown
caught
using:
throw
try-catch
java.lang.Exception
Exception inherits from Throwable.
It represents recoverable problems.
Examples:
divide by zero
file not found
invalid inputSerializable
Exception implements Serializable interface.
What is Serializable?
It allows objects to be converted into:
byte stream
so they can be
saved into file
sent through network
transferred between systems
Example Analogy
Serializable = packing object into a box
object converted into bytes
stored or transferred
later unpacked back
Complete Hierarchy Diagram
Object
↓
Throwable
↓
Exception
↓
ArithmeticException
↓
ArrayIndexOutOfBoundsException
Simple Analogy
Imagine family tree:
Object → Grandfather
Throwable → Father
Exception → Son
ArithmeticException → Grandson
Inheritance passes downward.
Exception is a class inside java.lang package that inherits from Throwable, which itself inherits from Object, and it implements the Serializable interface.
Top comments (0)