HakiDocs
Java

Compiler VS Runtime Error

Difference between Compiler and Runtime

Imagine you're writing.
a highly detailed script.
for a play 🎭.
The java compiler is the Script Editor,
and the JVM/Runtime is the actual Performance Director.

Before the first rehearsal even begins,
the java compiler reviews the manuscript.
They look for grammatical mistakes,
misspelled character names,
or impossible stage directions.

The JVM takes the _perfectly edited script.
and starts the actual performance.
Everything is fine until an actor is told to
divide the props in half—but the prop count is zero.
Or, the script tells the actor to find a file backstage,
but the file was deleted yesterday.

The script was grammatically correct,
but the instruction is impossible to execute in the current environment.

Conclusion

If the error is about Java's grammar and rules, the Compiler catches it before a .class file is even created. If the error is about an impossible action or a missing resource during execution, the JVM throws a Runtime Error (an Exception).

🦕 Sources 


On this page