Page 88 - CA_Blue( J )_Class10
P. 88
You will get the following output:
5.6 ERRORS IN JAVA
Sometimes, while programming in Java, we come across certain situations or code that results in an illegal operation
or execution of the program or outputs a wrong answer. These are known as errors or bugs in Java. In other words, an
error is an abnormal condition that can stop the execution of a program or produce an abnormal output. It is necessary
to find and remove all the errors so that the program works normally and generates the required output. The process
of finding and removing errors or bugs from a program is known as debugging. In Java, there are three types of errors:
Errors
Syntax Errors Logical Errors Runtime Errors
5.6.1 Syntax Errors
The errors that occur due to violation of the syntax rules of the Java programming language are called syntax errors. In
other words, if there are some grammatical errors while coding, then the type of error that occurs is known as a syntax
error. Syntax errors are also known as compile-time errors because these errors are reported by the compiler at the
time of compiling a program. Java compiler will not allow the program to execute if any syntax error is present in the
program. So, it has to be removed before execution. It is very easy to find and correct syntax errors.
Some of the common causes of syntax errors are: Definition
• absence of a semicolon at the end of a statement
double rate_of_interest = 7.8 Syntax means a set of rules that we have to
• absence of the closing curly bracket of any block of code follow to work in a programming language. It is
void display( ) similar to the English language grammar.
{
System.out.println("Welcome Touchpad");
• absence of double quotes
System.out.println("Java is a programming language);
• absence of + operator while concatenating two strings
System.out.println("String 1" "String 2");
• Using an incorrect spelling of a keyword
Sytem.out.print(" ");
• Using an undefined variable
int a = 10;
int b = 20 ;
c = a + b; //c is undefined
8686 Touchpad Computer Applications-X

