Repaso
EspaƱol
Java CoreCoreJV-02

"Write once, run anywhere" in Java is possible mainly because:

Options

  1. Java code is translated to each OS's machine code on every edit
  2. The compiler makes bytecode, and each OS has a JVM that runs it (Correct option)
  3. Java programs only work on Windows, which hides the differences
  4. Java has no operating system dependencies at all, so nothing is needed

Answer

The compiler produces bytecode, and each OS has its own JVM that can run the same bytecode

Why

javac compiles your code to bytecode, a neutral instruction set. The same .class or .jar file can be copied to Windows, Linux or macOS.

Each platform has its own JVM that translates bytecode to what that computer understands.

So you compile once; the JVM handles the differences between machines.

Remember

Bytecode is portable; the JVM is platform-specific.

Key terms

Practice this question in Repaso