It is a well known fact that Java is a platform independent programming language. The meaning of this statement is that the java compiled code(byte code) will run on all operating systems. A Java program or snippets is typically written in a language that is considered to be a human readable programming language. It will always contain words, phrases, etc which the machine doesn't perceive. For the source code to be understood by the machine, it has to be in a language which is understandable by machines and computers, generally a machine-level language. So, here comes the role of a compiler. The compiler converts this high level programming language (human language) into a format understood by the machines. Therefore, a compiler is a program that interprets the source code for another program from a programming language into executable code.
Java programming language's executable code is seen as a sequence of machine instructions which will be executed by the CPU directly or it should be an intermediate representation that is comprehended and interpreted by a virtual machine. This intermediate representation in Java is known as the Java bytecode. One can understand the working of Java by taking up the advanced Java course.
Now that we have covered how Java codes are executed in every platforms. We would like to state that,"Java is platform independent programming language, but JVM is platform dependent." To simplify this statement, JVM depends on the operating system. JVM varies according to the operating system in which the java program is executed. The fact is that when downloading the JVM for your computer, you will given a list of JVMs with situable compatibility according to the operating system. It is obviously that you will choose the JVM that is compatible with your computer's OS. Now it should be clear for you and we conclude that JVM is platform dependent which is why Java is able to be platform independent.