Reputation: 444
I have read enough explanation about the definition of compiler, interpreter and "things" that use both. I didn't find how compiler and interpreter both are used in one language.
Upvotes: 5
Views: 7147
Reputation: 607
Java is one of the first machine independent programming languages; it uses both compiler and interpreter. Java compilers are designed in such a way that converts source code into platform independent form i-e byte codes. These byte codes are then converted to machine code by interpreter. This is how compiler and interpreter both used in one language. Any system having JVM will run these byte codes.
Java program byte code interpreted by VM machine language
summary :
java compiler convert source code in to an intermediate language known as bytecode. This bytecode only can be executed in a virtual environment called JVM. Java virtual machine. JVM is an interpreter to java bytecode. It converts bytecode into machine language and executes line by line.
this is how both compiler and interpreter used in one language..if it found useful you may mention
Upvotes: 4
Reputation: 11610
In Java the source code is first compiled to bytecode and then it's run by an interpreter (JVM - Java Virtual Machine).
bytecode is machine code for a virtual machine.
In Javascript there's a runtime (engine) that does just in time compilation (JIT). Basically, at execution time it's given a source code which it immediately converts to native code and then the code is executed. In Chrome's engine there are two modules that do compilation: one can execute code fast but the code isn't much optimized (ignition interpreter) and the other produces a highly performant code but compilation takes more time (turbofan compiler).
Why use both:
Upvotes: 4