Learn
Debugging
Syntax Errors
When we are writing Java programs, the compiler is our first line of defense against errors. It can catch syntax errors.
Syntax errors represent grammar errors in the use of the programming language. They are the easiest to find and correct. The compiler will tell you where it got into trouble, and its best guess as to what you did wrong.
Some common syntax errors are:
- Misspelled variable and method names
- Omitting semicolons
;
- Omitting closing parenthesis
)
, square bracket]
, or curly brace}
Here’s an example of a syntax error message:
Debug.java:5: error: ';' expected
int year = 2019
^
1 error
Usually the error is on the exact line indicated by the compiler, or the line just before it; however, if the problem is incorrectly nested braces, the actual error may be at the beginning of the nested block.
Instructions
1.
Try compiling the code and find the syntax error in Debug.java.