How is Java platform independent?

When you compile Java programs using javac compiler it generates bytecode. We need to execute this bytecode using JVM (Java Virtual machine) Then, JVM translates the Java bytecode to machine understandable code.

You can download JVM's (comes along with JDK or JRE) suitable to your operating system and, once you write a Java program you can run it on any system using JVM.