Why Java is both compiled and interpreted language when the JIT also compiles the bytecode?

Ragul picture Ragul · Jan 2, 2014 · Viewed 18.5k times · Source

I read that, a java source code is compiled into 'bytecode' then it is 'Compiled' again by JIT into 'machine code'. That is, the source code is first compiled into a platform independent bytecode and then compiled again to a machine specific code. Then why it is called as both interpreted and compiled language? Where the interpretation takes place?

Answer

Aniket Thakur picture Aniket Thakur · Jan 2, 2014

There is a bit of misunderstanding here.

In normal circumstances java compiler(javac) compiles java code to bytecodes and java interpreter(java) interpretes these bytecodes(line by line), convert it into machine language and execute.

JIT(Just in time) compiler is a bit different concept. JVM maintains a count of times a function is executed. If it exceeds the limit then JIT comes into picture. java code is directly compiled into machine language and there on this is used to execute that function.