Reputation: 101
I know how JVM interprets byte codes to machine code,so brings platform independency. But, I want to know how JVM comes on the system?
i. Is it a pre-existing executable program file resides inside JRE?So, do we need to install JRE, to get the JVM program on my system?
or, ii. what does it mean by 'once .java file gets compiled, a jvm instance gets created?' Does it mean that JVM doesn't pre-exist inside JRE but within an allocated memory area of JRE, a mimic/emulate of the actual CPU(of host system) gets created at run-time, which is known as JVM?
Please confirm how JVM comes in the picture?
iii.Also, I want to know what does it mean by 'instance of JVM?
Upvotes: 1
Views: 453
Reputation: 1252
JVM is:
A specification :-where working of Java Virtual Machine is specified. But implementation provider is independent to choose the algorithm. Its implementation has been provided by Sun and other companies.
An implementation :-Its implementation is known as JRE (Java Runtime Environment).
Runtime Instance:- Whenever you write java command on the command prompt to run the java class, and instance of JVM is created.
Upvotes: 0
Reputation: 106508
Is it a pre-existing executable program file resides inside JRE? So, do we need to install JRE, to get the JVM program on my system?
The Java Runtime Environment is indeed a separate program that needs to be installed on your computer. When you get the JRE, you get the JVM (which is where your programs will execute).
What does it mean by 'once .java file gets compiled, a jvm instance gets created?' Does it mean that JVM doesn't pre-exist inside JRE but within an allocated memory area of JRE, a mimic/emulate of the actual CPU(of host system) gets created at run-time, which is known as JVM?
It's a virtual machine that does indeed pre-exist in the JRE. You can have as many applications running Java on your machine at once, and they're going to be executed on different instances of the JVM. I would argue that compilation may not create a new instance of the JVM (it might, but I'm not certain), but executing a Java application (or even the same Java application multiple times) will definitely create new instances of the JVM.
Upvotes: 2
Reputation: 692191
The JRE is the JVM + standard libraries every Java application has access to.
So yes, when you install the JRE, you're also installing the JVM.
Every time you launch
java com.foo.Bar
you're starting a new instance of the JVM, and this JVM instance executes the Bar
class passed as argument. You can have several Java programs executing in parallel on your machine, and each java program has its own instance of JVM, isolated from the other ones.
Upvotes: 2
Reputation: 20520
The JVM is part of the JRE. The program that loads up a JVM gets installed when you install a JRE.
An instance of a JVM is a currently executing JVM. You have one executable to launch a JVM, but you might have run it lots of times concurrently. Each time it's run, a new instance gets created; when the JVM terminates, the instance gets destroyed.
Upvotes: 2