The following compiles fine in my Eclipse:
final int j = 1/0;
// compiles fine!!!
// throws ArithmeticException: / by zero at run-time
Java
It's legal because no where is it a given that the compiler is supposed to fold constant expressions at compile time.
A "smart" compiler might compile:
a = 1 + 2
as
a = 3
But there's nothing that says the compiler HAS to do that. Other than that, 1/0 is a legal expression just like:
int a;
int b;
a = a/b;
is a legal expression.
At RUNTIME it throws an exception, but that's a runtime error for a reason.