What are the differences between Syntax error and Logical error in Java.
Answers
The difference between a syntax error and logical error is that the syntax error occurs due to an error in the syntax of a sequence of characters or tokens that is intended to be written in a particular programming language while a logical error is an error that occurs due to the fault in the program.
Answer:
When programming, there can be errors. An error is an unexpected output of the program. These errors can affect the proper execution of the program. Therefore, it is necessary to remove all errors. An error is also called as a bug. The process of identifying errors and fixing them is called debugging. Each programming language has a specific syntax. The programmer should follow the correct syntax to write programs. When there is syntax mistake, it is known as a syntax error. A syntax error occurs at compile time. The error that occurs at runtime is called a runtime error. Array out of bound, diving by zero, accessing memory that is not available are some examples of runtime errors. When writing a program, there is a sequence of steps to follow to solve the problem. This methodology is called an algorithm. If the logic of the program is wrong, it will give incorrect output. That kind of an error is known as a logical error. This article discusses the difference between a syntax error and a logical error. The key difference between syntax error and logical error is that, the syntax error occurs due to an error in the syntax of a sequence of characters or tokens that is intended to be written in a particular programming language while logical error is an error that occurs due to the fault in the program algorithm or the logic.