There are three types of error: syntax error, run-time error, and logic error. We will discuss each of these in the following section.
1. Syntax Error
Errors that are detected by the compiler are called syntax errors or compilation errors. It results from errors in code construction such as mistyping a keyword, omitting some necessary punctuation, or using an opening brace without a corresponding closing brace.
Example:
Identify a syntax error in the following program.
public class Trial {
public static main (String[] args) {
System.out.println("Welcom to Java World")
}
}
2. Runtime Errors
Runtime errors are errors that cause a program to terminate abnormally. They occur while a program is running if the environment detects an operation that is impossible to carry out.
Example:
In the following program, division by zero will cause runtime error.
public class Trial {
public static main (String[] args) {
System.out.println(6/0);
}
}
3. Logic Errors
Runtime errors are errors that cause a program to terminate abnormally. They occur while a program is running if the environment detects an operation that is impossible to carry out.
Example:
In the following program, division by zero will cause runtime error.
public class Trial {
public static main (String[] args) {
System.out.println(6/0);
}
}
1. What is the difference between Syntax Errors and Logic Errors?
2. What is the difference between Run-time Errors and Compilation Errors?