Hi dear coders! What's java virtual machine ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Hi dear coders! What's java virtual machine ?

JVM

15th Aug 2018, 7:33 PM
Saeed Vahid
Saeed Vahid - avatar
3 Answers
+ 1
TL;DR: A program that executes Java byte code. When you compile a programming language like C you are compiling into a format like ELF (Linux, ELF executable) or PE (Windows, EXE file). This format tells the Operating System how the program should be loaded into memory. Once the program is loaded, the CPU starts executing it. The CPU reads instructions and data in it's own architecture-specific format. So you have 2 things you have to worry about when compiling a C program: what OS is it going to run on and what architecture. If you are trying to port an application sometimes that can be painful. Not to mention, in order to do anything except manipulate text, you have to use APIs specific to that OS. If you want to draw a window on Linux you use X, but on Windows you use Win32. In order for people to write platform-agnostic code they came up with the idea of a virtual machine. Instead of compiling to code that would be loaded by the OS and executed by the CPU it is instead executed by the VM, which (1/2)
15th Aug 2018, 8:05 PM
Vlad Serbu
Vlad Serbu - avatar
+ 1
is a program in and of itself. This is what Java does. Instead of having to port all Java programs to a new architecture or operating system, they just have to port the JVM (which is written in C, the most popular language in the world, next to Java itself). This is why, for example, you can get the Minecraft launcher binary and run it on Windows or Linux, on Intel x86 or a Raspberry Pi, without changing it at all.
15th Aug 2018, 8:08 PM
Vlad Serbu
Vlad Serbu - avatar
0
what's a good answer?,thank you that was completely useful and usefully complete.
15th Aug 2018, 10:13 PM
Saeed Vahid
Saeed Vahid - avatar