Intro to Java Programming, Comprehensive Version (10th Edition)

Author: Y. Daniel Liang
3.8
This Year Stack Overflow 1

Comments

by anonymous   2018-03-19

Here is a quote from Daniel Liang, author of 'Introduction to JAVA programming', on the subject of compilation:

"A program written in a high-level language is called a source program or source code. Because a computer cannot execute a source program, a source program must be translated into machine code for execution. The translation can be done using another programming tool called an interpreter or a compiler." (Daniel Liang, "Introduction to JAVA programming", p8).

...He Continues...

"A compiler translates the entire source code into a machine-code file, and the machine-code file is then executed"

When we punch in high-level/human-readable code this is, at first, useless! It must be translated into a sequence of 'electronic happenings' in your tiny little CPU! The first step towards this is compilation.

Simply put: a compile-time error happens during this phase, while a run-time error occurs later.

Remember: Just because a program is compiled without error does not mean it will run without error.

A Run-time error will occur in the ready, running or waiting part of a programs life-cycle while a compile-time error will occur prior to the 'New' stage of the life cycle.

Example of a Compile-time error:

A Syntax Error - how can your code be compiled into machine level instructions if they are ambiguous?? Your code needs to conform 100% to the syntactical rules of the language otherwise it cannot be compiled into working machine code.

Example of a run-time error:

Running out of memory - A call to a recursive function for example might lead to stack overflow given a variable of a particular degree! How can this be anticipated by the compiler!? it cannot.

And that is the difference between a compile-time error and a run-time error