I have some confusion about compilation and Interpretation and also the way JIT works. I know that the source code or the Java Program gets compiled to Java Byte Code which is then loaded onto JVM which then either interprets the bytecode to native machine code or uses JIT.
I was going through Interpreter doc and understood that an Interpreter analyses each statement on every request and then converts to native code leading to slower performance.
And also read that JIT does dynamic translation and stores the native code on a cache which is then used for subsequent requests.
What I wanted to understand was that how exactly JIT works? Whenever a first request is made to an application then it converts that part of byte code to machine code, stores on cache and uses it.. Is this the process? If so then, is every first request always slower as it needs translation of bytecode to machine code?
Please explain this in detail.