GeeCON Prague 2014*
The moose likes Beginning Java and the fly likes What is JVM? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is JVM?" Watch "What is JVM?" New topic
Author

What is JVM?

Pal Sudarshan
Ranch Hand

Joined: Jun 10, 2004
Posts: 52
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.
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
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).


SCJP Tipline, etc.
sever oon
Ranch Hand

Joined: Feb 08, 2004
Posts: 268
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is JVM?