Search⌘ K

Kinds of Errors

Explore the common types of programming errors in Java, such as syntax, semantic, and runtime errors. Understand how these errors affect your code and learn foundational debugging methods to identify and resolve these issues effectively.

We'll cover the following...

Syntax errors

Just like any natural language, such as English, Java has a set of rules that define it. These rules form the language’s syntax. They dictate how we form phrases and statements. If we do not follow Java’s syntax precisely, we will have made a syntax error, and our program will not compile. The compiler will produce a message that attempts to describe what we have done wrong. Most of the time, these error messages will point right to the mistake, but sometimes the messages might seem vague or even misleading. Because the compiler generates a message when it first detects that something is incorrect, it cannot always diagnose the problem specifically. However, we can be sure of one thing: The compiler is right; we made a mistake!

📝 Note
Compilers detect syntax errors. Any errors detected by a compiler are compile-time errors.

Semantic errors

Even if we follow all of Java’s grammatical rules—its syntax—thereby passing the compiler’s scrutiny, we might not get the results we desire or expect. It is possible for ...