Interview questions

Is Java a compiled language or an interpreted one?

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.


  1. Java Compiler (javac) compiles Java code to Bytecode (which is platform-independent).
  2. Java Interpreter (java) interprets this bytecode (line-by-line) & convert it to Machine language.
  3. Execute.

Exception: JIT (Just In Time) Compiler

  1. JVM maintains the count for no of times a function is executed.
  2. If it exceeds the limit then JIT directly compiles the Java code into Machine language. No Interpretation.

In General,

• Compile: Source code >> Optimized Object Code (can be machine code or other optimized code)
• Interpret: Source Code >> Machine Code (to be executed)