Java Interview Question

Why is Java called platform independent?

Updated 2026-07-10 · Beginner friendly
Quick answer

Java is platform independent because you compile your code once into bytecode rather than machine code. That bytecode runs on any device that has a JVM, and each operating system has its own JVM. This is the write once run anywhere idea, since the same compiled file works on Windows, Mac, and Linux.

How it works

When you compile Java you do not get code for a specific processor. You get bytecode, an intermediate form. The JVM on each machine translates that bytecode into instructions the local hardware understands, so your program does not care what machine it runs on.

// Source (.java)  ->  javac  ->  Bytecode (.class)  ->  JVM  ->  runs anywhere

The bytecode is the same everywhere. What changes is the JVM, which is built for each platform. That is the clever split that gives Java its portability.

In the interview

Say the phrase write once run anywhere, then explain that bytecode is portable while the JVM is platform specific. Being able to name bytecode as the reason, not just repeat the slogan, is what separates a strong answer.

Want the full Java guide?

Read every Java concept with notes, diagrams, and code in one place. Track your progress as you go.

Open the Java guide All Java questions