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?
Java can be considered both a compiled and an interpreted language because its source code is first compiled into a binary byte-code. This byte-code runs on the Java Virtual Machine (JVM), which is usually a software-based interpreter.
Both compilers and interpreters are used to convert a program written in a high-level language into machine code understood by computers.
Java is first machine independent programming language; 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.
Static compilation converts the code into a language for a specific platform. An interpreter directly executes the source code. JIT compilation attempts to use the benefits of both. While the interpreted program is being run, the JIT compiler determines the most frequently used code and compiles it to machine code.
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.
It has a specification (the JLS) that defines how Java programs should act.
As a language itself, it does not specify how it should be executed on different platforms. The way it runs, with a JIT or without a JIT is entirely implementation based.
If I write a Java runtime tomorrow that does not do JIT compilation at all I can call Java interpreted.
If I take a Java machine (and people seriously made those) that uses Java bytecode as assembly, I can call Java strictly compiled.
A lot of other languages do this:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With