...

/

More Compile-Time Errors

More Compile-Time Errors

In this lesson, we will continue looking at common syntax errors in Java and what causes them.

Missing parenthesis

Suppose we accidentally omit the closing parenthesis from a println statement. For example, consider the program below. Notice the result of its compilation after you click the RUN button.

Press + to interact
public class Debug8
{
public static void main(String[] args)
{
System.out.println("Welcome!";
} // End main
} // End Debug8

The compiler is precisely correct in identifying the mistake!

What if we had omitted the opening parenthesis instead, so that the program appears as shown below. Click the RUN button.

Press + to interact
public class Debug9
{
public static void main(String[] args)
{
System.out.println"Welcome!");
} // End main
} // End Debug9

Although the error messages do not mention a missing parenthesis, hopefully they will help you to see the mistake.

Missing brace

Braces, like parentheses, must occur in open-close matching pairs. The program shown below has two open braces but only one close brace. Click the RUN button to see how the compiler handles this situation.

Press + to interact
public class Debug10
{
public static void main(String[] args)
{
int anInteger = 10;
System.out.println("The integer is " + anInteger);
} // End main

The word parse means to analyze syntactically. The error message indicates that the compiler ...

Access this course and 1400+ top-rated courses and projects.