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.
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Difference between Thread.start() and Thread.run() in Java
- How to Compile and Run C/C++/Java Programs in Linux
- Difference between Compile-time and Run-time Polymorphism in Java
- How to run java class file which is in different directory?
- Run-time Stack mechanism in Java
- How to run Java RMI Application
- Overloading of Thread class run() method
- How to run two animations simultaneously in jQuery ?
- Elements that occurred only once in the array
- How to Make an Activity Appear Only Once in Android?
- Why to use char array over a string for storing passwords in Java?
- Why Java is not a purely Object-Oriented Language?
- Why Constructors are not inherited in Java?
- Why Kotlin will replace Java for Android App Development
- 8 Reasons Why You Should Switch To Kotlin From Java
- Why can't static methods be abstract in Java?
- Why You Should Switch to Kotlin from Java to Develop Android Apps?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. 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.