What's the difference?
So what is the difference between a compiled program and an Interpreted one?
Compiling
To write a program takes these steps:- Edit the Program
- Compile the program into Machine code files.
- Link the Machine code files into a runnable program (also known as an exe).
- Debug or Run the Program
With some languages like Turbo Pascal and Delphi steps 2 and 3 are combined.
Machine code files are self-contained modules of machine code that require linking together to build the final program. The reason for having separate machine code files is efficiency; compilers only have to recompile source code that have changed. The machine code files from the unchanged modules are reused. This is known as Making the application. If you wish to recompile and rebuild all source code then that is known as a Build.
Linking is a technically complicated process where all the function calls between different modules are hooked together, memory locations are allocated for variables and all the code is laid out in memory, then written to disk as a complete program. This is often a slower step than compiling as all the machine code files must be read into memory and linked together.
Interpreting
The steps to run a program via an interpreter are- Edit the Program
- Debug or Run the Program
Enter Java and C#
Both of these languages are semi-compiled. They generate an intermediate code that is optimized for interpretation. This intermediate language is independant of the underlying hardware and this makes it easier to port programs written in either to other processors, so long as an interpreter has been written for that hardware.
Java when compiled produces bytecode that is interpreted at runtime by a Java Virtual Machine(JVM). Many JVMs use a Just-In-Time compiler that converts bytecode to native machine code and then runs that code to increases the interpretation speed. In effect the Java source code is compiled in a two-stage process.
C# is compiled into Common Intermediate Language (CIL, which was previously known as Microsoft Intermediate Language MSIL. This is run by the Common Language Runtime (CLR), part of the .NET framework an environment that provides support services such as garbage collection and Just-In-Time compilation.
Both Java and C# employ speedup techniques so the effective speed is almost as fast as a pure compiled language. If the application spends a lot of time doing input and output like reading disk files or running database queries then the speed difference is barely noticeable.
0 comments:
Post a Comment