javajvmjitinterpreted-language

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


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?


Solution

  • 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.