What are the differences between a Just-in-Time-Compiler and an Interpreter?

Rookian picture Rookian · Mar 11, 2010 · Viewed 26.8k times · Source

What are the differences between a Just-in-Time-Compiler and an Interpreter, and are there differences between the .NET and the Java JIT compiler?

Answer

Colorfully Monochrome picture Colorfully Monochrome · Nov 18, 2014

I've always found that a more abstract explanation sometimes helps. Let's say that you are trying to ask everyone in Mexico "Hello. How are you?" (your source language) Of course, you'll first need to translate it to Spanish (the native language of the country). That translation would be "Hola. Como estas?"

If you know Spanish, there would be no need for you to translate (native code / assembler). You just ask "Hola. Como estas?"

If you don't know Spanish, there are 3 ways to deal with it.

The first is to get a Spanish Dictionary (a compiler) and look up what the Spanish words are before you go. Perhaps you realize that "Hola. Que tal?" is one syllable shorter (compiler optimization) and use that instead. This is language compilation; you are converting the information to the native language beforehand.

The second is where you look up the words in the Spanish Dictionary while you are standing in front of the first person and then store the result (looking up the words just-in-time). The advantage here is that you could get a Mandarin Dictionary and then do the same experiment in China without having to keep ten sticky notes (binaries for different platforms) of translated phrases.

The third is where you look up the words while you are standing in front of each person. In essence, you interpret the words for each person separately (you act as an interpreter). The advantage here is that any changes are instantly reflected with the next person (you could change to asking "Hello. What color is your dog?" without having to fly home and restart - you don't need to recompile the phrases).

  • Translating beforehand means you can ask people fastest (pre-compiliation); you don't need to even bring the dictionary with you.
  • Translating when you see the first person in each country is almost as fast as translating beforehand but still allows you to travel to multiple countries without needing to go home to get a dictionary but means that you need to bring several dictionaries with you (a platform independent runtime).
  • Translating on demand is much slower but allows you to change the words without traveling home (source distributed language).