Java Zero to All All questionsPractise free
Interview questions › Java Foundations — Zero to Basics › How Java Runs — JDK, JRE, JVM & Your First Program

What does 'write once, run anywhere' mean and how does Java achieve it?

Level I · BeginnerHow Java Runs — JDK, JRE, JVM & Your First Program
Short answer

You compile your source once into platform-neutral bytecode (.class files), and that same bytecode runs on any machine that has a JVM, without recompiling.

Explanation

Java achieves it by inserting the JVM as a layer between your program and the OS: javac targets the abstract JVM instruction set instead of a specific CPU, and each OS ships its own JVM that translates that bytecode into native instructions at run time. The bytecode is the same everywhere; only the JVM underneath differs.

Common mistakes
  • Claiming Java is interpreted line by line — modern JVMs JIT-compile hot code to machine code.
  • Saying 'run anywhere' means no testing on other platforms is ever needed.

Can you say this out loud in two minutes? Drill it in a timed mock interview, with flashcards and runnable code for How Java Runs — JDK, JRE, JVM & Your First Program.

Practise free

More on How Java Runs — JDK, JRE, JVM & Your First Program