What are the various types of errors in Java?
Topic: Types of errors
Answer
Three types: (1) Syntax errors (compile-time errors) — the rules of the language are broken, for example a missing semicolon. The compiler reports them and no .class file is produced. (2) Runtime errors (exceptions) — the program compiles but fails while running, for example division by zero or an array index out of bounds. (3) Logical errors — the program compiles and runs perfectly but gives the wrong result, for example using + where * was intended.
Name all three and give an example of each; the examples are what separate a full-mark answer from a half one. The useful way to hold them apart is WHEN each is discovered: syntax errors before the program runs, runtime errors during execution, logical errors only when you check the output. Logical errors are the hardest to find precisely because nothing complains.