So far we have discussed how a program is loaded into virtual memory, started as a process kept track of by the operating system and interacts with via system calls.
A program that can be loaded directly into memory needs to be in a straight binary format. The process of converting source code, written in a language such as C, to a binary file ready to be executed is called compiling. Not surprisingly, the process is done by a compiler; the most widespread example being gcc™.
Compiled programs have some disadvantages for modern software development. Every time a developer makes a change, the compiler must be invoked to recreate the executable file. It is a logical extension to design a compiled program that can read another program listing and execute the code line by line.
We call this type of compiled program a interpreter because it interprets each line of the input file and executes it as code. This way the program does does not need to be compiled, and any changes will be seen the next time the interpreter runs the code.
For their convenience, interpreted programs usually run slower than a compiled counterpart. The overhead in the program reading and interpreting the code each time is only encountered once for a compiled program, whilst an interpreted program encounters it each time it is run.
But interpreted languages have many positive aspects.
Many interpreted languages actually run in a
virtual machine
that is
abstracted from the underlying hardware. Python and Perl 6 are
languages that implement a virtual machine that interpreted code
runs on.
A compiled program is completely dependent on the hardware of the machine it is compiled for, since it must be able to simply be copied to memory an executed. A virtual machine is an abstraction of hardware into software.
For example, Java is a hybrid language that is partly compiled and partly interpreted. Java code is complied into a program that runs inside a Java Virtual Machine or more commonly referred to as a JVM. This means that a compiled program can run on any hardware that has a JVM written for it; so called write one, run anywhere.