Write Once, Run Anywhere” — In Brief

This means – Write Java code once, run it on any OS (Windows, Linux, Unix) without changing code

How it works

  • Java compiles .java → bytecode (.class)
  • Bytecode is platform-independent
  • Each OS has its own JVM that runs this bytecode

Can I compile on Windows and run on Linux/Unix?

✔️ Yes — absolutely

  1. Write & compile on Windows:

javac Hello.java   → Hello.class

  1. Copy Hello.class to Linux/Unix
  2. Run:

java Hello

-> It will run as-is, as long as a compatible JVM is installed.

Small Caveats

  • Same Java version compatibility (e.g., Java 11 class → needs Java 11+ JVM)
  • OS-specific things (file paths, native libraries) may need adjustment

In short

Java = Compile once → Run anywhere via JVM abstraction layer

Leave a Reply

Your email address will not be published. Required fields are marked *