Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Which one is JVM ?  RSS feed

 
Subhendu Dash
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Was going through Java SE Documentation..there it is mentioned that JVM is present with JRE which in turn is a part of JDK.Now when i see my JDK1.4/bin folder, i can see java and javaw tool present within it.Now both java and javaw are also present with jdk1.4/jre/bin folder.
So with this i have two questions:
1-Since java tool is used to run a particular .class file.So is it correct to say that java tool is the JVM that executes my .class file?
2-If yes,then at run time which JVM is used ? the one present inside jdk/bin or the present at jdk/jre/bin
?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Subhendu Dash wrote:1-Since java tool is used to run a particular .class file.So is it correct to say that java tool is the JVM that executes my .class file?

No. The java.exe and javaw.exe are just small programs to start up the JRE to run a Java program. Where exactly the implementation of the JVM itself is, isn't something that you normally need to know. I just looked in my JDK installation directory and found a jvm.dll in the jre/bin subdirectory.

Subhendu Dash wrote:2-If yes,then at run time which JVM is used ? the one present inside jdk/bin or the present at jdk/jre/bin ?

I don't know exactly. What exactly do you hope to learn with the answer to this question?

You could compare it to a car. The JVM (Java Virtual Machine) is the engine, the JRE (Java Runtime Environment) is the complete car, including the engine. The JVM is what's actually executing the bytecode of your program. But you need all the stuff around it, such as the standard Java library, to really run your program. Just like you need a complete car, not just an engine, if you want to drive somewhere.
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you using jdk1.4? Get an up to date version, like 7.
The java tool starts the JVM; you could try going through the JVM Specification, or google for bcel manual to find out which programs are run from the java tool. That is probably implementation‑dependent, in which case you won’t find out, and knowing it does not help you.
As for which version of java is executed: whichever is found first going through your PATH environment variable. That java program starts whichever JVM it starts, and again you don’t need to know those details.
 
Subhendu Dash
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Subhendu Dash wrote:2-If yes,then at run time which JVM is used ? the one present inside jdk/bin or the present at jdk/jre/bin ?

I don't know exactly. What exactly do you hope to learn with the answer to this question?


Just curious to know what executes my class's bytecode ..
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Subhendu Dash wrote:Just curious to know what executes my class's bytecode ..

And Jesper answered that:

Jesper de Jong wrote:The JVM is what's actually executing the bytecode of your program.
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Subhendu Dash wrote: . . . I don't know exactly. What exactly do you hope to learn with the answer to this question? . . .
There is something peculiar about that post; I think you have missed some quote tags.

I have already told you which JVM runs: whichever is called by the first java tool in your PATH. Try echo %PATH% (Windows) or echo $PATH (*nix) at a terminal to be reminded what your PATH is.
 
Subhendu Dash
Greenhorn
Posts: 18
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for answering my queries..appreciate it..!!
Well to sum it, Java and javaw are just tools(and not the JVM) that start the JRE which in turn invokes the JVM to execute our .class file.And which JDK is called depends upon the path that we have specified in environment variables(Windows) properties.

And i know we don't really need to know this..but where exactly is the implementation of the JVM?
 
Lexington Smith
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ! I did not want to hijack this post. It heard that the java.exe is the JVM (which you say is incorrect) and javac.exe is the compiler. What is correct then ?
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure whether java is the JVM or part of it or simply a program to start the JVM. You can start it with javaw, too, so the JVM may be another program started by each of those tools. The java and javaw tools in my Windows installation are 189 and 194 kB, so I suspect that is too small to be the whole JVM. But I am not sure. Anyway, it is an implementation detail which you don’t need to know about.
I think you would have to google for a download of the entire code for the JVM; it is open source and therefore freely available. Somebody else might remember where you can find it.
 
Tony Docherty
Bartender
Posts: 3268
82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It heard that the java.exe is the JVM (which you say is incorrect) and javac.exe is the compiler. What is correct then ?

java.exe (and javaw.exe) starts the JVM, javac.exe starts the Java compiler.
The how, why, what and where are irrelevant, all you need to know is if you want to compile your Java code you use javac.exe and if you want to run your compiled code you use java.exe (or javaw.exe).
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16028
87
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:I think you would have to google for a download of the entire code for the JVM; it is open source and therefore freely available. Somebody else might remember where you can find it.

You can find the complete source code for the JVM, JRE and JDK from OpenJDK. But it's a huge project and it's not going to be easy to understand.
 
fred rosenberger
lowercase baba
Bartender
Posts: 12542
48
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jesper de Jong wrote:You can find the complete source code for the JVM, JRE and JDK from OpenJDK. But it's a huge project and it's not going to be easy to understand.

Correct me if I am wrong, but isn't that the source code for a JVM, JRE, and JDK? As in, there are more than one, and each would have different source code.
 
Campbell Ritchie
Marshal
Posts: 55698
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And each would have a different java/javac/javaw tool, which might perform different proportions of the work. As Tony Docherty and I have already said, you do not actually need that information.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!