2

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

Colin Hebert
  • 91,525
  • 15
  • 160
  • 151
JavaUser
  • 25,542
  • 46
  • 113
  • 139
  • possible duplicate of [Runtime vs Compile time](http://stackoverflow.com/questions/846103/runtime-vs-compile-time). Also note that your request regarding java and c is difficult wither way I interpret (heh!) it. Neither java nor c is usually interpreted, and describing the work of either type of program in those languages takes a small book. – dmckee --- ex-moderator kitten Oct 10 '10 at 10:18
  • Languages typically cannot be categorized as interpreted or compiled. Most languages can be both interpreted and compiled. This distinction only comes into play when we talk about a specific implementation. – svenningsson Oct 13 '10 at 18:23

2 Answers2

1

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
  • 6,134
  • 4
  • 33
  • 55
  • 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 Oct 10 '10 at 08:07
  • You COULD, but most languages are either designed to be compiled or to be interpreted. – Alexander Rafferty Oct 10 '10 at 08:08
  • 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 Oct 10 '10 at 08:10
  • 1
    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 Oct 10 '10 at 08:15
  • 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 Oct 10 '10 at 08:42
  • 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 Oct 10 '10 at 14:35
1

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

Community
  • 1
  • 1
DarkDust
  • 90,870
  • 19
  • 190
  • 224