Exception handling allows you to manage runtime errors using:
try
, catch
, finally
, throw
, throws
try {
int a = 5 / 0;
} catch (ArithmeticException e) {
System.out.println("Cannot divide by zero");
}
IOException
)NullPointerException
)Java automatically deallocates memory for unused objects using garbage collection. It improves memory efficiency and reduces memory leaks.