You can write a program in Java once and then execute it on any platform that offers the environment for it to run. In other words, Java code is platform-independent provided the environment, i.e. Java Virtual Machine (JVM), is present. You need to note here that, even though Java is platform-independent, JVM is not. JVM is different for different platforms. A Java program is compiled as byte code, which is platform-independent. JVM executes this byte code which helps any underlying operating system (platform) understand the code. So essentially, Java Virtual Machine helps the platform understand the Java program through the compiled result, which is byte code.