I'm learning Java and following things are bit confusing for me.What i understood is:
Java Compiler->Java compiler just convert .java programs into .class files, that means converting our source code into byte code(it is a list of op codes for the virtual machine(JVM) which makes java, platform independent).
Java Interpreter-> merely "interprets" the code and DOES NOT transform it into native machine code. It executes each and every instructions one by one of the byte code as a command and carries it out regardless how many time a same instruction occurs.(That's why it's slow and java introduces JIT concept.)
JIT Compiler->This also comes into picture at execution time.JIT is able to improve performance through caching results of blocks of code that has been TRANSLATED – compared to simply re-evaluating every line or operand in the Bytecode each time that it occurs.
Now I've several questions.
1. As my physical processor understands only native machine code how a java program gets executed using JVM's Interpreter as interpreter doesnt convert byte code to native machine code.Untill and unless someone places the machine code into memory, physical processor won't be able to execute it.
2.Supposing, somehow, interpreter also converts ByteCode to native machine code then "Block of code execution with caching(JIT) and line by line execution(Interpreter)" is the only thing that differenciates JIT and interpreter?
3.If, at execution time, a JIT translates bytecode to native machine code(for executing the program) why didn't java use ahead of time compilation like after generating JVM dependent bytecode(Which in-turn makes java Plateform independent),bring it on target machine(where we want to execute it) and just translate it to native machine code( making .exe or .out etc as in case of C compilation).This could be possible because we're having a specific JVM on every system.This would be much faster than using JIT as it takes some time in compiling/loading the program and it will still be platform independent by just distributing Bytecode(generated before final translation from Bytecode to M/c Code).
forgive me if its a silly question.