Forums Register Login

What is JVM?

+Pie Number of slices to send: Send
I have read many programmers talk of JVM. What exactly is JVM? I thought there was a java class compiler and java interpreter, but never realized that there was this JVM.
+Pie Number of slices to send: Send
JVM stands for Java Virtual Machine. Basically, the JVM is the interpreter - it creates a layer between you and the OS so that, no matter what the underlying OS is, you program as if you're on the same OS, the "virtual" OS. Hence the name, JVM. (Honestly, I don't know if that's really how it got it's name, but it's how I remember it. )

I'm moving this to Java in General (Beginner).
+Pie Number of slices to send: Send
Actually, the JVM is more than just a "virtual OS"...it's exactly as the name implies, it's a virtual machine. The JVM is a piece of software that simulates a computer...as in the hardware CPU. If you know anything about assembly at all, then you'll get immediately what this means (if you don't, then you might find the next few sentences a little dense).

When you write a C program, you must compile (and then link, but let's keep things simple) that program to "binary code". Binary code is a sequence of 1s and 0s that, when divided up into 8-bit chunks (bytes), are meaningful to the processor. The Intel 80386 chip, for instance, might recognize 01101001 as the instruction "add the next two numbers", and then it waits for the next two numbers (maybe 00000000 and 00000001) and makes the result (00000001) available. When you write code in assembly, you are only one level away from typing in 1s and 0s...the main difference between writing assembly and a long string of 0s and 1s is that the assembler translates words like "add" in your program into its corresponding bit pattern.

Different processors have different codes associated with operations. So on Intel, "add" might be associated with the byte I wrote above, but on a Motorola chip it might be a totally different bit pattern.

The Java compiler compiles whatever programs you write into "bytecodes" (I'm sure you've heard this term). Bytecodes are essentially binary code for the software CPU that is the JVM. Why simulate a computer in software, though, when there's a perfectly good computer you could use directly? The reason: platform independence. The JVM allows you write code that, once compiled, will run on the JVM. In C, though, you have to compile a program several times if you want it to run on several platforms. In Java, there's only one "hardware" machine you have to worry about, the JVM. (The JVM itself is not platform independent--it must take the bytecodes you supply it and translate it into binary machine code for the machine on which it is running--that's why when you download the JVM you must get a different one if you're running a Mac than if you're running a PC.)

sev
Just let me do the talking. Ahem ... so ... you see ... we have this tiny ad...
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1288 times.
Similar Threads
Security in java
jvm and jre diffrence
jvm
Is JDK same for all platforms(windows,unix,mac) or is it different for different operating systems.
Core Java
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 05:43:07.