Written by nitinpai on September 3rd, 2007
And I thought I Knew How Java Worked!
I did till today, and realized that many concepts are still unknown to me as well as some of my friends who have worked on Java EE for a long time now. I have learnt many frameworks along the course from the day I started my professional work in J2EE (now christened JEE). Java in its core form never came across me as I was eager to find out the challenges that I faced while working with JEE. It is sometimes interesting to see your much loved aspect, turning out on your face and looking like a complete stranger to you.
It was in the morning that my colleague asked me that he had taken an interview where he asked the question to the interviewee,
What is the difference between JVM and JRE?
Of course, it was Java Virtual Machine and Java Run Time Environment, I said without a second thought. But it doomed to me like never before, what next was their difference? Was it something that SUN had planned to demystify my confidence in the world of Java. Reluctantly, yet diplomatically I said to him that I knew the difference but I would like his point of opinion. He said something which I half heartedly believed, putting on a note in my mind the quest for the day to find the interesting answer to this seemingly easy but notorious question. The answer he relented was,
JVM is a specification and JRE is an implementation. JVM is just like the Servlet or the JSP specification provided by SUN and JRE is the implementation that is OS specific. JVM is not installed, but JRE is.
The last line left me gasping for breath. Until now I had been installing JVM and also had seen the JRE folder in C:/Java, but today I failed to recollect what the heck was JRE and how in the world I could install a JVM, as supposedly said by my colleague.
I went to the office to quench the thirst of my curiosity. I was ablaze with surprise when I searched and found the exact same words that my colleague had said to me. This came from the Java Forum. I thought it was maybe the right one. Enlightened with this, I called upon another colleague of mine and asked him as to put him to the judgment grill. The question remained the same but the answer did not. It was another baffling one,
Do you know you can download JVM too. Now don’t try to act smart. Just Google it and you will come to know.
And Google did answer it by religiously giving me the set of links to download JVM. But none of them were from the creator itself i.e SUN. It was turning out a little fishy in this. Now came the moment to test download JRE and to my relief, the first link was of SUN. Thankfully the query had been resolved to a partial satisfaction that maybe the first answer had really been true.
Little was my confidence boosted when my colleague intriguingly asked me another,
Did you know that your JRE is capable of running your class files without the need of a JDK. I have done that and they ran like any normal program would.
I gawked at him in amazement. It was like getting bedazzled with someone pounding you like a heavy weight boxer. But having no mercy he went on saying,
I have been able to run Eclipse and write Java programs without having JDK in my system. I have seen there is no javac in JRE folder but still I was able to create a Java Project and run it in Eclipse.
Bewilderment was taking a toll on my brain and I was at the brink of saying that I love Microsoft and .NET, when he said that he was also amazed at this but did not know the right answer. Phew! something to cheer about, at last. It is good to know that somebody else in your surrounding is feeling the same pain in the butt and telling you about it.
One thing was clear, my knowledge lacked the essence of core Java as some of them who searched the forums to find a relieving answer. And as lucky as I could get I got one such nicely explained statement from which, I hopefully came to know what was the difference between JVM and JRE, in JGuru forum,
JVM forms part of large system JRE. It comprises a set of base class which are implementation of base java API, as well as JVM. JVM is used for running the java software with the availablity of JRE which is different in a given environment. JVM’s main job is interpreting java bytecode and translating this into actions or OS calls.
This I found was the correct definition and further to clear my doubts I found one more resource which gave out a formal explanation with a set of diagrams to clarify the point being made. The point of concern are as follows:
- The Java Virtual Machine is responsible for interpreting Java bytecode, and translating this into actions or operating system call.
- The Java Virtual Machine forms part of a large system, the Java Runtime Environment (JRE). Each operating system and CPU architecture requires a different JRE.
- The JRE comprises a set of base classes, which are an implementation of the base Java API, as well as a JVM
- Without an available JRE for a given environment, it is impossible to run Java software.
In short and sweet words, I can now say that JRE is like the motherboard and JVM is like your processor which powers your computer. You can never have a processor and motherboard catering to different architecture. And although each entity is a different component of your computer, both have to run in tandem to bring the power of computing to reality.
Now I somewhat know how Java works!