Syntax Errors

🙋 Need help? Ask an expert now!

Let's take a look at the example below, which will show us the last of the three most common errors, a Syntax Error.
package exlcode;

public class SyntaxErrorExample {
    // public cannot be capitalized
    // ints should be int
    Public static ints exampleVariableOne = 5;

    // static cannot be capitalized
    public Static void main (String[] args){
        // printline should be println
        System.out.printline("Value of exampleVariableOne is " + exampleVariableOne);

  public static int exampleVariableOne = 5;

  public static void main(String[] args) {
    System.out.println("Value of exampleVariableOne is " + exampleVariableOne);

The code above shows a different set of variables and main method than the one outside the comments. The code inside the comments has syntax errors and would not compile if the comments were removed. A syntax error is similar to a grammatical error in the language of programming. One of the most common syntax errors is the misuse of Java reserved words. The program will compile but will then throw an error when seeing misformatted reserved words. Other syntax errors include misspelled variable and function names, missing semicolons, and mis-matching parentheses.

Syntax errors are among the easiest to resolve as most IDE tools we use to write Java point out syntax errors as you code.

Edit Me on GitHub!

Application Question

Which one of these method headers would cause a syntax error?