Compile-time versus runtime errors
What you will learn
A compile-time error prevents successful compilation; a runtime error occurs while executing a compiled program. A logic error can produce an incorrect result even though the program compiles and runs.
public class Main { public static void main(String[] args) { System.out.println("Checked"); }}Expected output:
CheckedThe semicolon terminates the statement.
How it works
When a compiler reports an error, inspect the first relevant diagnostic and the nearby source. At runtime, an exception can report its type and stack trace. For incorrect output, compare actual behavior with an independently calculated expected result. The first example fixes a missing semicolon; the second illustrates a logic error with valid syntax.
public class Main { public static void main(String[] args) { System.out.println(18 - 5); }}Expected output:
13The expression subtracts borrowed items instead of adding them.
Common mistakes
A successful compilation does not establish that the answer is correct. The valid expression 18 + 5 would be wrong if five items were removed from stock.
Try it yourself
Predict the correct remaining stock when 24 items are available and 9 are lent. Write the program and compare its output.
These are local Java practice tasks, not automatically graded ByteMind exercises. Use a patched JDK; no network or third-party dependency is needed.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Compile-time versus runtime errors — knowledge check
Check your understanding of compile-time versus runtime errors.
A missing required semicolon is usually which kind of error?
The program prints 23 instead of 13 but exits normally. What should you inspect?