I am new in programming language, especially in Java. I am reading a java book and find a theory about Interpreter and Compiler. Could anyone explain different between them.

Thanks,

August 14th, 2014, 12:30 AM

ChristopherLowe

Re: Difference between Interpreter and Compiler

Welcome to the forums!

A big part of learning how to program is research and self learning. The good news that the largest library ever created is a google search away. Why don't you do a bit of reading and come back with your own understanding of the difference between the two and then we will have a discussion about things you don't fully understand.

August 14th, 2014, 02:55 AM

xturtle

Re: Difference between Interpreter and Compiler

Hello ChristopherLowe,

Thanks for your advice. I have red several articles about them. The main point is the interpreter execute and translate the high level language into machine language line by line and show up if there is an error, but compiler execute all of codes and running it, and also show up if there is an error.

one question from me,

When we use interpreter and compiler ? because both same translate codes to machine language.

Thanks,

August 14th, 2014, 03:41 AM

GregBrannon

Re: Difference between Interpreter and Compiler

Quote:

When we use interpreter and compiler ?

Some languages are interpreted, some are compiled. You don't make the choice except by choosing which language to use.

Quote:

because both same translate codes to machine language.

Sometimes there's an intermediate step. Java compiles to byte code which is interpreted by a JVM specific to the using computer's OS and processor.

August 14th, 2014, 03:49 AM

xturtle

Re: Difference between Interpreter and Compiler

okay, I see. It depend on language to use.

sip Greg Brannon, thanks for your explanation.

August 14th, 2014, 04:54 AM

GregBrannon

Re: Difference between Interpreter and Compiler

Just to be complete, there are occasional compilers for languages that are typically interpreted, but I don't believe they've been reliably maintained for any length of time.

August 14th, 2014, 06:52 AM

ChristopherLowe

Re: Difference between Interpreter and Compiler

Quote:

Originally Posted by xturtle

Hello ChristopherLowe,

Thanks for your advice. I have red several articles about them. The main point is the interpreter execute and translate the high level language into machine language line by line and show up if there is an error, but compiler execute all of codes and running it, and also show up if there is an error.

one question from me,

When we use interpreter and compiler ? because both same translate codes to machine language.

Thanks,

Not quiet correct. A compiled language turns the source code into native machine code which can be directly executed by the hardware. An interpreted language compiles the source code into something that can be read by an interpreter and then converted into machine code.

For example, C is a compiled language. The gcc compiler converts .c files to executable binaries and as such you need to target the cpu architecture at compilation. Java on the other hand an interpreted language. The javac compiler turns .java file into bytecode called .class files. Then it's up to the Java runtime environment to interpret the bytecode and turn it into executable machine code on the fly.

The advantage of the Java interpreted paradigm is you can leave native hardware details up to the JRE, whereas is C you typically compile separately for each target platform with a bunch of IFDEF's to handle different system architectures. The disadvantage of interpreted languages is that the users need special software, such as the JRE to run the program. There is also an (arguably inconsequential) performance overhead with interpreted languages compared to compiled ones because there is the extra step of interpretation.