This note is (obviously) generated by ChatGPT, but it’s a neat overview of the types of errors that could occur in Java.
🧱 Compile-Time Errors (Detected during compilation)
🧠 Think: “Syntax and type rules broken” — Java can’t even build the program.
🔹 Types
-
Syntax Errors
-
Missing semicolons
-
Unmatched brackets/braces/parentheses
-
Incorrect use of Java keywords
-
-
Type Errors
-
Incompatible types (e.g., assigning a
doubleto anintwithout a cast) -
Calling a method with the wrong parameter types
-
Using undeclared variables
-
-
Missing Class or Method Definitions
-
Trying to instantiate an undefined class
-
Calling a non-existent method
-
-
Access Errors
-
Trying to access private members from outside the class
-
Using incorrect static vs. non-static context
-
💥 Runtime Errors (Occur while the program is running)
🧠 Think: “Program builds but crashes during execution”
🔸 Types
-
NullPointerException
- Accessing a method or field of a
nullreference
- Accessing a method or field of a
-
ArithmeticException
- Division by zero
-
ArrayIndexOutOfBoundsException
- Accessing an array index that doesn’t exist
-
ClassCastException
- Improper casting between unrelated types
-
IllegalArgumentException
- Passing invalid arguments to methods (common in math/util libraries)
-
StringIndexOutOfBoundsException
- Accessing invalid index of a string (e.g.,
charAt(-1)orcharAt(length))
- Accessing invalid index of a string (e.g.,