Difference between Compiler Error & Runtime Exception
Joined: Jun 21, 2006
I wanted to know the difference between Compiler Error & Runtime Exception. Given a faulty program that how do you identify if it is a Compiler Error or a Runtime Exception ?
Joined: Apr 25, 2005
Compiler error could be a syntax error 1. Left curly braces not equal to right curly braces. 2. Semicolon missing in the end. 3. identifiers starting with digits. 4. Using wrong modifiers (top level class private) or wrong combination of modifer (abstract with static).
These are some error which compiler can catch.
In short compiler error are those which directly violate any rule of java language specification.
Whereas exception comes when something goes wrong at the time of execution of your code. You code is fine as per JLS but may be you are doing 1/0 arithmetic operation or loading any class or file which does not exist.
Compiler can't report these errors unless and until you programme not gets executed. We call these types of errors as Exception.
"By the way its not certification question at all. Its java beginner question" and we have separate forum for that.