Two Laptop Bag
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Difference between Compiler Error & Runtime Exception Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Difference between Compiler Error & Runtime Exception" Watch "Difference between Compiler Error & Runtime Exception" New topic

Difference between Compiler Error & Runtime Exception

Poonam Krishnam

Joined: Jun 21, 2006
Posts: 1
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 ?
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
Hi Poonam,

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.

[ July 13, 2006: Message edited by: Naseem Khan ]

Asking Smart Questions FAQ - How To Put Your Code In Code Tags
wise owen
Ranch Hand

Joined: Feb 02, 2006
Posts: 2023
What is the difference between compile time error and run time error?
I agree. Here's the link:
subject: Difference between Compiler Error & Runtime Exception
It's not a secret anymore!