Compile-Time Errors
In this lesson, we will explore some common syntax errors in Java and the messages they cause a compiler to generate.
We'll cover the following...
Common mistakes
We begin this lesson by listing the following mistakes in Java’s syntax, because they are easy to make, particularly for someone just learning Java:
- Missing semicolons. Each Java statement must end in a semicolon, just as English statements end in a period.
- Extra semicolons. An extra semicolon sometimes causes no harm, as the compiler simply ignores it. However, a misplaced semicolon can cause a problem.
- Capitalization. Java is case-sensitive, meaning our use of uppercase and lowercase letters matters. All Java reserved words are lowercase. Spelling one using one or more capital letters is incorrect. Any identifiers that we use must be consistent in their case.
- Spelling. Errors while typing Java reserved words or variable names, for example, are typically flagged as unidentified symbols.
- Mismatched parentheses or braces. Each open parenthesis or brace must match a corresponding close parenthesis or brace, respectively. Usually, an IDE’s editor will help us to avoid this error, but if we make it anyway, the compiler will complain.
Access this course and 1400+ top-rated courses and projects.