JVM(Java Virtual Machine) acts as a run-time engine to run Java applications. JVM is the one that actually calls the main method present in Java code. JVM is a part of the JRE(Java Runtime Environment).
Java applications are called WORA (Write Once Run Anywhere). This means a programmer can develop Java code on one system and can expect it to run on any other Java-enabled system without any adjustment. This is all possible because of JVM.
How Java is WORA:
In traditional programming languages like C, C++ when programs were compiled, they used to be converted into the code understood by the particular underlying hardware, so If we try to run the same code at another machine with different hardware, which understands different code will cause an error, so you have to re-compile the code to be understood by the new hardware.
In Java, the program is not converted to code directly understood by Hardware, rather it is converted to bytecode(.class file), which is interpreted by JVM, so once compiled it generates bytecode file, which can be run anywhere (any machine) which has JVM( Java Virtual Machine) and hence it gets the nature of Write Once and Run Anywhere.
Example: Practical Implementation of WORA using a simple JAVA program to check whether a number is even or odd.
- For Compiling (done on Windows 10):
- After compilation there will be a class file in the corresponding folder named as:
- When copied the bytecode (.class) generated on compilation to a macOS 10.14.3 and running it we get the following output.
To sum it up, Java, when compiled, creates a bytecode (.class file), which can be run in any machine which supports JVM. So once compiled it doesn’t require re-compilation at every machine it runs, JVM converts the bytecode to be understood by the underlying hardware.
- Java.util.LinkedList.poll(), pollFirst(), pollLast() with examples in Java
- Java lang.Long.numberOfLeadingZeros() method in Java with Examples
- Java lang.Long.highestOneBit() method in Java with Examples
- Java lang.Long.byteValue() method in Java with Examples
- Java lang.Long.numberOfTrailingZeros() method in Java with Examples
- Java lang.Long.reverse() method in Java with Examples
- Java.util.concurrent.RecursiveTask class in Java with Examples
- Java.lang.Short toString() method in Java with Examples
- Java.util.Collections.disjoint() Method in java with Examples
- Java.util.Collections.rotate() Method in Java with Examples
- Java.util.LinkedList.peek() , peekfirst(), peeklast() in Java
- Java.util.concurrent.RecursiveAction class in Java with Examples
- Java.util.function.BiPredicate interface in Java with Examples
- Java.util.function.IntPredicate interface in Java with Examples
- Java.util.function.LongPredicate interface in Java with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.