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.



Try compiling the code and find the syntax error in Debug.java.

Take this course for free

Mini Info Outline Icon
By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.

Or sign up using:

Already have an account?