aspose file tools*
The moose likes Beginning Java and the fly likes JDK, JVM and JRE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JDK, JVM and JRE" Watch "JDK, JVM and JRE" New topic
Author

JDK, JVM and JRE

Vaibhav G Garg
Ranch Hand

Joined: Sep 23, 2011
Posts: 140
I am confused about JRE and JVM. As per my understanding, JDK is required to build and compile the programs. I have following queries related to JVM and JRE:

But, I am not sure about the functions of the JVM and JRE?

And, who provides the JVM and JRE? Is it SUN (ORACLE) or third party vendor like Microsoft for Windows OS provides the JVM/JRE?

What are the contents of JVM and JRE?

I know this is very basic but I want to clear the basics so I have posted it over here. I have asked a couple of guys but none of them were clearly explained it.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19693
    
  20

Please SearchFirst. This question has been asked and answered before. I think we even have an FAQ about it.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Vaibhav G Garg
Ranch Hand

Joined: Sep 23, 2011
Posts: 140
Thanks Rob! I am new to the forum. I have found the related posts.

Below are the useful links I have found related to this which can be helpful to others as well:

http://www.coderanch.com/t/538022/java/java/JDK-JRE-JVM

http://www.coderanch.com/t/562835/java/java/Java-Basic#2555555

Vaibhav G Garg
Ranch Hand

Joined: Sep 23, 2011
Posts: 140
http://docs.oracle.com/javase/1.5.0/docs/

This link describes the pictorial representation of JDK, JVM and JRE.
Vaibhav G Garg
Ranch Hand

Joined: Sep 23, 2011
Posts: 140
I have seen on a couple of machines that we get an error while we launch some java applications that JRE is not installed on the machine. So, I have a couple of queries related to JRE/JVM:

i. Who develops the JVM? Is it SUN Microsystems or the OS Vendor?

ii. Who develops the JRE? I know we get JRE versions for different OS on Sun's Website.

iii. I heard that JVM is provided by every OS. Is that true? Since JVM is a part/subset of JRE, so, how will it communicate with the JRE we will install ourselves? And, if we install some JRE ourselves, and also, the JVM is provided by the OS vendor, then which JVM will be picked up by JRE as JVM is a part of installed JRE?

Thanks in advance.
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1506
    
    5

Hello VaibhavG Garg,

I'm not expert in this area, however, below is my understanding:

VaibhavG Garg wrote:i. Who develops the JVM? Is it SUN Microsystems or the OS Vendor?

Well, nobody develops JVM. JVM is just a specification - specifying what an implementation of JVM should do. JRE is an implementation of JVM (e.g. Oracle, MySQL, DB2 etc. are implementations of a specification named RDBMS).

VaibhavG Garg wrote:ii. Who develops the JRE? I know we get JRE versions for different OS on Sun's Website.

Now, since JRE is an implementation of JVM, technically, anybody can develop JRE(of course, there is a specific procedure if you want to develop it - and another procedure if you want to distribute it commercially). However, in reality, generally OS vendors do not develop JRE - e.g. Microsoft does not develop JRE for Windows - it is provided by SUN (now Oracle).
What basically happens is - when we compile a Java file, the compiler converts Java code in a byte-code. This byte-code is nothing but instructions which are understandable by an implementation of JVM (i.e. JRE). As per Java's 'compile once run everywhere' philosophy, this byte-code (i.e. .class file) is similar irrespective of platforms. The reason is quite simple - this is byte-code for JVM, not for OS.
Now, when we run the compiled class file, JVM/JRE comes into picture. The job of JRE is - to read byte-code, and convert it into another byte-code which is understandable by underlying OS. Clearly, byte-code understood by Windows is different than that understandable by Linux implementation (like Ubuntu, RehHat etc.).
Popular implementations of JVM are - Oracle JRE, IBM JRE, HP JRE etc. Of course the most popular is Oracle - because its free and most of the development is done in Oracle JDK.

VaibhavG Garg wrote:iii. I heard that JVM is provided by every OS. Is that true? Since JVM is a part/subset of JRE, so, how will it communicate with the JRE we will install ourselves? And, if we install some JRE ourselves, and also, the JVM is provided by the OS vendor, then which JVM will be picked up by JRE as JVM is a part of installed JRE?

No. JVM is not provided by OS. It can be provided by a vendor for one or more OS, but as mentioned above, Microsoft has nothing to do with JRE provided by Oracle for Windows.
No. JRE is not part/subset of JVM. JRE is implementation of JVM. Just like Windows is not part of OS, but Windows is an implementation of a concept called OS.

I hope this helps.


Regards,
Anayonkar Shivalkar (SCJP, SCWCD, OCMJD, OCEEJBD)
Vaibhav G Garg
Ranch Hand

Joined: Sep 23, 2011
Posts: 140
Thanks Anayonkar for your response.

Anayonkar Shivalkar wrote:
Now, when we run the compiled class file, JVM/JRE comes into picture. The job of JRE is - to read byte-code, and convert it into another byte-code which is understandable by underlying OS. Clearly, byte-code understood by Windows is different than that understandable by Linux implementation (like Ubuntu, RehHat etc.).


Just a simple (or silly) question here, The JRE converts byte code to OS understanding code or machine code understandable by the processor?

Anayonkar Shivalkar wrote:

No. JVM is not provided by OS. It can be provided by a vendor for one or more OS, but as mentioned above, Microsoft has nothing to do with JRE provided by Oracle for Windows.
No. JRE is not part/subset of JVM. JRE is implementation of JVM. Just like Windows is not part of OS, but Windows is an implementation of a concept called OS.



But, if we notice the diagram here, http://docs.oracle.com/javase/1.5.0/docs/
It displays that JVM is inside the JRE. What does this in diagram then signifies?
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Vaibhav G Garg wrote:Thanks Anayonkar for your response.

Anayonkar Shivalkar wrote:
Now, when we run the compiled class file, JVM/JRE comes into picture. The job of JRE is - to read byte-code, and convert it into another byte-code which is understandable by underlying OS. Clearly, byte-code understood by Windows is different than that understandable by Linux implementation (like Ubuntu, RehHat etc.).


Just a simple (or silly) question here, The JRE converts byte code to OS understanding code or machine code understandable by the processor?


Machine code. I don't know what you would even mean by "OS understanding code." As far as I know, most OSes don't have their own language.


Anayonkar Shivalkar wrote:

No. JVM is not provided by OS. It can be provided by a vendor for one or more OS, but as mentioned above, Microsoft has nothing to do with JRE provided by Oracle for Windows.
No. JRE is not part/subset of JVM. JRE is implementation of JVM. Just like Windows is not part of OS, but Windows is an implementation of a concept called OS.



But, if we notice the diagram here, http://docs.oracle.com/javase/1.5.0/docs/
It displays that JVM is inside the JRE. What does this in diagram then signifies?


To me it signifies that different people have different understandings or interpretations of those terms.

Off the top of my head, I don't know for sure what the official Oracle terminology is, but as far as I understand it, "JVM" is really properly just a specification, but it it also often used to refer to a program that implements that specification, and the JRE is an environment that consists of a JVM implementation, the core Java API libraries, and any native code (.DLL, .so, etc.) required by the JVM and by the APIs.

So, in short, I agree with you that a JVM (or perhaps more properly a JVM implementation) is one piece of a JRE.
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1506
    
    5

Vaibhav G Garg wrote:Just a simple (or silly) question here, The JRE converts byte code to OS understanding code or machine code understandable by the processor?

Well, technically, the byte-code is understandable by processor - i.e. assembly language. But different OS treats resources differently. e.g. Linux treats all resource as files, Windows does not do it. Also, there are file system differences etc. What I'm saying is that the byte-code is different as per different OS. But of course, byte-code language depends on processor. e.g. for Intel processors, it will be X86 assembly language and so on.
Vaibhav G Garg wrote:But, if we notice the diagram here, http://docs.oracle.com/javase/1.5.0/docs/
It displays that JVM is inside the JRE. What does this in diagram then signifies?

Frankly speaking, I never saw that diagram very closely But it appears to me as kind of some layered architecture diagram and not much related to Java packaging. e.g. 'java' utility is part of JRE, however, in the diagram, it is outside of JRE.

I hope this helps.
Vaibhav G Garg
Ranch Hand

Joined: Sep 23, 2011
Posts: 140
Thanks Jeff for clarifications.

Jeff Verdegan wrote:I don't know what you would even mean by "OS understanding code." As far as I know, most OSes don't have their own language.


I am sorry for the ambigous statement here. By "OS understanding code", I meant the native operating system calls which OS will use to do some operations on the processor. I am not sure about this.
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1506
    
    5

Jeff Verdegan wrote:Machine code. I don't know what you would even mean by "OS understanding code." As far as I know, most OSes don't have their own language.

I might be putting it in wrong words, but what I wanted to say is:
If there is a file handling code in Java, then when it is converted in machine level code by JRE, it is converted in language depending on processor, but since different OS does file handling in different ways, the actual assembly code will be different for different OS (unlike class files - which are same for all OS).
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Vaibhav G Garg wrote:Thanks Jeff for clarifications.

Jeff Verdegan wrote:I don't know what you would even mean by "OS understanding code." As far as I know, most OSes don't have their own language.

I am sorry for the ambigous statement here. By "OS understanding code", I meant the native operating system calls which OS will use to do some operations on the processor. I am not sure about this.


Ah okay. That's still machine code understood by the processor. It's OS-specific libraries written in or, more likely, compiled to, that CPU's machine language. So Linux on an x86 CPU might store its running processes starting at address 1234 in a map type of structure and Windows might store them starting at address 2468 in a tree type of structure. The specific sequence of instructions used to get a list of processes or find a particular process will be different between the two OSes' respective libraries, but those sequences of instructions will all consist of the same set of x86 machine language instructions.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Anayonkar Shivalkar wrote:
Jeff Verdegan wrote:Machine code. I don't know what you would even mean by "OS understanding code." As far as I know, most OSes don't have their own language.

I might be putting it in wrong words, but what I wanted to say is:
If there is a file handling code in Java, then when it is converted in machine level code by JRE, it is converted in language depending on processor, but since different OS does file handling in different ways, the actual assembly code will be different for different OS (unlike class files - which are same for all OS).


Right. The language will depend only on the processor, but the steps executed using that language will vary across different OSes using the same processor. Same language, different system-level library implementations.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

So going back to this:

Vaibhav G Garg wrote:
Just a simple (or silly) question here, The JRE converts byte code to OS understanding code or machine code understandable by the processor?


The byte code gets converted to machine code that is understood by the particular processor (the machine code for "copy the value from address1 to address2" will be the same on any OS using that processor), but the specific sequences of instructions will only have meaning and give desired behavior in the OS for which they are targeted (Windows will not use address1 and address2 for the same thing that Linux does).
Vaibhav G Garg
Ranch Hand

Joined: Sep 23, 2011
Posts: 140
Thanks Jeff and Anayonkar! I am really sorry if I am bothering you guys too much.

Now, as per my understanding, .class file will first be converted into some intermediary Assembly Code depending upon the OS. And, then this Assembly code will be finally converted into machine code. And, hence the JRE will only depend upon the underlying OS and it will be the OS responsibility to convert that intermediary code to machine level code. This is because we have JRE based on different OS versions. Please correct if I am mistaken anything.

Also, if I compile a .java file on Windows and the same .java file on Unix then will the generated .class files be the same?
Anayonkar Shivalkar
Bartender

Joined: Dec 08, 2010
Posts: 1506
    
    5

Vaibhav G Garg wrote:Thanks Jeff and Anayonkar!

You are welcome.
Vaibhav G Garg wrote:I am really sorry if I am bothering you guys too much.

Not at all. I'm also a learner, and answering questions in public forum is one of the best thing to improve knowledge
Vaibhav G Garg wrote:Now, as per my understanding, .class file will first be converted into some intermediary Assembly Code depending upon the OS. And, then this Assembly code will be finally converted into machine code.

No. Class file itself is intermediary byte-code which is understandable by JRE. JRE, during run time, further converts it into final byte-code. As mentioned earlier, the language of that byte-code is dependent on processor, and the instruction sequence is dependent on OS. Please note that assembly code is machine code.

The only reason JRE is OS dependent is - while converting .class file in machine instructions, JRE must be aware of what kind of sequence to use - hence, JRE meant for Windows does not need to understand what is the instruction sequence for Linux and so on.

I hope this helps.
Vaibhav G Garg
Ranch Hand

Joined: Sep 23, 2011
Posts: 140
Anayonkar Shivalkar wrote:I hope this helps.


Yes Anayonkar, it really helped. Thanks a lot.

Also, if I compile a .java file on Windows and the same .java file on Unix then will bothgenerated .class files be the same?
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7781
    
  21

Vaibhav G Garg wrote:Also, if I compile a .java file on Windows and the same .java file on Unix then will bothgenerated .class files be the same?

As far as I know: yes. That's one of the main foundation stones of Java - platform independence.

Winston


Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4543
    
    5

Winston Gutkowski wrote:
Vaibhav G Garg wrote:Also, if I compile a .java file on Windows and the same .java file on Unix then will bothgenerated .class files be the same?

As far as I know: yes. That's one of the main foundation stones of Java - platform independence.

Winston


They may not be identically the same if compiled with a different compiler.

If compiled with the same version of Oracle's (or Sun's) javac, they can be expected to be identical.


luck, db
There are no new questions, but there may be new answers.
Vaibhav G Garg
Ranch Hand

Joined: Sep 23, 2011
Posts: 140
Thank you all of you for clarifying the doubts.
Vaibhav G Garg
Ranch Hand

Joined: Sep 23, 2011
Posts: 140
Hi Guys, I am sorry to put some confusion again. I have read it at some places over internet that JRE converts byte code into machine code. While at some places, it is written JVM converts byte code into machine code. So, who actually converts byte code to machine code: is it JVM/JRE?

Also, do JVM physically exist? Since it is just a specification which is implemented by JRE. So, what will be the contents inside the JVM?
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14146
    
  18

Look at it this way:

JVM = Java Virtual Machine = the engine of a car
JRE = Java Runtime Environment = a complete car, including the engine

If you want to drive somewhere, then you need more than just the engine of a car. You need a complete car. Likewise, to run a Java program, you need a JRE, which consists of a JVM with everything around it that is needed to operate it.

The JVM is really the heart of the JRE, the part that executes Java bytecode, and that translates Java bytecode to native machine code that the CPU in your computer can execute directly.

Vaibhav G Garg wrote:Also, do JVM physically exist? Since it is just a specification which is implemented by JRE. So, what will be the contents inside the JVM?

It exists as a piece of software. Whether software in general exists as a physical entity is a larger philosophical discussion, which is interesting, but off-topic for this forum thread.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Vaibhav G Garg
Ranch Hand

Joined: Sep 23, 2011
Posts: 140
Thanks Jesper for the clarification. It is clear to me now.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JDK, JVM and JRE