Monday, January 21, 2008 09:41 AM
In all cases, programs have to be executed at the machine code level.
When one compiles a program, the compiler takes the code, parses it and converts it to tokens (sometimes) then to an object module which then gets converted into machine code and stored for execution.
In an interpreted languages, the interpreter parses a statement, then converts it into some intermediate state. The tokens in that intermediate state are mapped to some group of executable machine language statements that are executed. Which means the executable code is not stored for execution. It is "interpreted", and translated into instructions that have already been mapped to executable code.
Each time the interpreted language program executes, the Source has to be interpreted.
Then, you have languages like Java, C#, Pascal and others that convert the Source is converted to an intermediate "byte code" state. That "byte code" is stored. This "byte code" looks very much like an "assembler" language program. But it is machine independent. A "Virtual Machine" sits between the byte code and the actual machine. Each instruction in the byte code is "mapped" to a series of executable machine language instructions on the "target" machine. The source does not have to be "compiled" again and the byte code can be ported to any type of computer that has a "byte code interpreter" or Virtual Machine for that language.
One can see that in order of execution speed (from fastest to slowest) you have:
- Compiled programs - the the code is actually in the machine language itself.
- Byte code or VM programs - this is now becoming a close second to Compiled programs with all the look ahead features and optimization that can be done in the VM.
- Interpreted programs - with a multi step process each and every time a program has to be executed.
There are advantages an disadvantages to each type of programing paradigm.
Interpreted languages are quick and ususally easy to develop in. A very quick turn around. You enter code and run!!! But it's usually very slow. There are acutally C/C++, and even Fortran interpreters used for quick prototyping of routines...
Byte code languages are much faster and are portable to multiple platforms. But they are slower than compiled languages and often times not suitable for Operating System development or quick Number crunching programs unless they have API's directly compilied into machine language and optimized for it. Java wasn't the first "byte code" language, but it is one of the most widely known an used. There are projects now to even make C# a language that can be ported to Linux and Mac.... (not by Microsoft, but by some other fool hearted sould).
And interesting enough, some compiled programs are becoming byte code. C/C++ on .NET in some cases is compiled into byte code.
With the code optimization, look ahead executers in the VM etc etc, byte code languages are executing faster and faster.
Compiled programs are the fastest, but the excutable code is not portable to other machines. The write, compile, execute cycle is much longer than interpreted languages. However, a good IDE can reduce that considerably.
So much for my rant, here. Hope this helps.