Hi Ugur
To demonstrate the difference between runtime and compile time errors lets look at some simple code that causes these errors.
Compile time error The above code will cause a compile time error because a semicolon is missing in the highlighted line.
Runtime time error class RunTime
{
public static void main(
String args[])
{
int a=5;
int b=0;
int c=a/b; System.out.println("This will be a compile time error"+c);
}
}
The above code will give you a runtime error because in the line shown highlighted you are dividing a number by zero and assigning the same to an integer, thereby causing an ArithmaticException.
But notice that the above example will not cause a compile time error because the value assigned could have been something other than '0', say '2' which was shown in the CompileTime error program.
From the above two examples we can conclude that if the compiler can predict during compile time that an error will occur, such as an obvious error like a missing semicolon, it will result in a compile time error.
If the compiler cannot find any syntax error in your code, the program compiles fine.
Although the code causing a RunTime error may be syntatically correct, like the one in the RunTime example, but it might not be obeying the
Java language specifications when the expression is actually executed.