Compiled Code
: The programmer writes the code, a different program called the Compiler translates that into machine code (instructions specific to that CPU in the computer) before the programmer written code ever runs. Think of an.exe file. The pro is that since the computer
can execute the instructions instantaneously, it is incredibly fast. The con being that it becomes platform-specific. The same .exe file won't run on a Mac and you would
have to re-translate the original program. The same .exe file won't run on a Mac and you would have to re-translate the original program again. Interpreted Code
: In a purely interpreted language (like Python or early Ruby), there is no pre-translation. Instead, a program called an Interpreter reads your code line-by-line while the program is running, converts it into machine code, and then the machine runs it. The pro is that the same programmer-written code can now run on any computer as long as that computer has the right interpreter installed. The con is that it is slower. The computer has to "waste" time translating while it's trying to work. If you have a loop that runs 1,000 times, the interpreter translates those same lines 1,000 times.What Java does
: Java combines the two steps:javac HelloWorld.java. This will output HelloWorld.class intermediate
file that can't be directly understood by you or the computer. Only the JVM can understand this. java HelloWorld, the JVM interprets the bytecode, converting it into machine code that the computer can
understand. If the compiler sees a piece of bytecode being used a lot, it will use the JVM (HotSpot) JIT to compile that specific part into native machine code on
the fly so that it doesn't have to interpret it every time. Ahead-of-Time compilation
: Java also has tried Ahead-of-Time compilation. Java must be turned into Bytecode first. AOT is the process of taking that universal Bytecode and converting it into a native binary before you ship it. The most significant way AOT lives in Java today is through GraalVM. Why? In "Serverless" computing (like AWS Lambda), you want your code to start in milliseconds. A traditional JIT-based Java app might take seconds to start - which is too slow. GraalVM AOT makes Java competitive with languages like Go or Rust for these tasks.