A. Both. Confused? Yes, Java is both compiled as well as interpreted language. This is what makes it platform-independent. Java Code >> Compile (javac) >> Bytecode (portable code) >> Interpret (platform specific) >> Machine Code >> Execute.
- Java Compiler (javac) compiles Java code to Bytecode (which is platform-independent).
- Java Interpreter (java) interprets this bytecode (line-by-line) & convert it to Machine language.
Exception: JIT (Just In Time) Compiler
- JVM maintains the count for no of times a function is executed.
- If it exceeds the limit then JIT directly compiles the Java code into Machine language. No Interpretation.
• Compile: Source code >> Optimized Object Code (can be machine code or other optimized code)
• Interpret: Source Code >> Machine Code (to be executed)