In Java, the ArithmeticException is mainly thrown during arithmetic operations that result in illegal or undefined results, particularly division by zero using integer types.
The only arithmetic operation that can cause an ArithmeticException in Java is:
Integer division or modulus (%) by zero.
int a = 10; int b = 0; int c = a / b; // ❌ Throws ArithmeticException: / by zero
int x = 25; int y = 0; int z = x % y; // ❌ Throws ArithmeticException: / by zero
This exception occurs only with integer types (int, long, short, byte).
Floating-point division (float, double) does not throw an exception — it results in:
Infinity (for positive/negative division by zero), or
NaN (Not a Number).
double a = 10.0; double b = 0.0; System.out.println(a / b); // ✅ Outputs: Infinity
In Java, integer division (
/) or modulus (%) by zero are the operations that can throw anArithmeticException.
First read the answer fully, then try to explain it in your own words. After that, open a few related questions and compare the concepts. This method helps you remember the topic for a longer time and improves exam preparation.