what is virtual machine
The Java Virtual machine (JVM) is the virtual machine that run the Java bytecodes. The JVM doesn't understand Java source code, that's why you compile your *.java files to obtain *.class files that contain the bytecodes understandable by the JVM. It's also the entity that allows Java to be a "portable language" (write once, run anywhere). Indeed there are specific implementations of the JVM for different systems (Windows, Linux, MacOS, etc ), the aim is that with the same bytecodes they all give the same results.
JVM doesn't understand what you have written it only understand bytecodes. whenever you compile the .Java file automatically a .class file is generated which you can run on any computer like Mac or Windows everywhere that's why it is called wora ( write once run anywhere).