views:

27

answers:

2

hi,

What exactly the difference between interpreted and compiled language.For example I want print the numbers from 1 to 100 .How exactly the sequence of operations takes place in case of interpreter and compiler.

Further,If possible please provide me the steps in according to Java language and C language

Thx

+1  A: 

A compiled language is a language which converts the source code to machine code. Also known as a native application.

An interpreted language is a language which converts the source code to some intermediate. During the execution of the program, an interpretor runs the source code. Interpreted languages tend to be, but not always are, significantly slower than compiled languages. They are useful, however, for portability.

C is compiled, turning the source code:

for (int i=1;i<=100;i++) { printf("%d",i); }

into assembly, then into machine code. The processor fetches each machine instruction and executes it. This is very fast.

Java, however, converts source code to an intermidiate byte code. At run-time, it is run on a "virtual-machine", which can be slower than a native compiled application.

Alexander Rafferty
It's not tied to a language. You can write both interpreters and compiler for every language, although e.g. writing a compiler for a dynamic language that supports `eval` is harder than writing an interpreter. For example, there are [C interpreters](http://www.softintegration.com/support/faq/general.html) and [Java compilers](http://gcc.gnu.org/java/).
DarkDust
You COULD, but most languages are either designed to be compiled or to be interpreted.
Alexander Rafferty
Also, the "official" Sun compiler is also that, a compiler. It compiles your source into bytecode, and *that* has to interpreted by the VM. Examples for an interpreter would be Ruby, Python, Perl or bash.
DarkDust
Yes, real-world languages are normally primarily designed to be either compiled or interpreted, but according to programming language theory every language can have both interpreters and compilers. And BASIC (shudder) is a real-world example of a language that was once almost always interpreter-based but nowadays has more compilers.
DarkDust
Java is a cross between compiled and interpreted. It compiles to byte-code, but it is not completely compiled, for the cross-platformness.
Alexander Rafferty
Well this is a kind of a definition thing. First, one needs to distince between the Java compiler (for the language) and the Java Virtual Machine. So Java the language *is* compiled, but the result is *normally* interpreted (though a Just-In-Time Compiler does yield native code, compiled from the byte-code). The byte-code is op-code for the virtual CPU of a JVM, but there were plans by Sun (and even prototypes) that ran that byte-code natively. And for ARM, there's the [Jazelle extension](http://en.wikipedia.org/wiki/Jazelle) to run Java byte-code on the CPU. You see it's not just black/white.
DarkDust
+1  A: 

This already kind of a FAQ on StackOverflow :-)

For example, see the following answers:

What is the difference between implementing a compiler and an interpreter?

How does an interpreter/compiler work

DarkDust