wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes JRE Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "JRE Question" Watch "JRE Question" New topic
Author

JRE Question

Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 627
Hi All,

I was thinking JRE as a software implementation of JVM which runs the Java byte codes. But, I just noticed that it has a Compiler too? I wrote a Java program and put the .java file in JRE's bin folder(jre1.6.0_02\bin) and was able to compile and run it successfully. So JRE has a Compiler too?

Thanks.


Be Humble... Be Nice.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
I was thinking JRE as a software implementation of JVM which runs the Java byte codes. But, I just noticed that it has a Compiler too? I wrote a Java program and put the .java file in JRE's bin folder(jre1.6.0_02\bin) and was able to compile and run it successfully. So JRE has a Compiler too?


A Java Runtime Environment (JRE) is an implementation of the Java Virtual Machine specification (JVM). It is the JRE that executes a Java program, not the JVM. The JVM is just a specification.

There is a compiler in a JRE that compiles the class files and creates native code specific to the operating system. And, this is the code that is running on the machine (within the JRE).

The compiler to create class files from Java source files is "javac.exe". This is a separate executable and is not part of a JRE.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

I disagree that the JVM is only a specification.

The JVM (Java Virtual Machine) is the core of the Java system. It's like the microprocessor in a computer: the engine that executes the bytecode.

To be able to run Java programs, you need a JVM + the standard Java library classes + some other infrastructure around it. These things together are the JRE (Java Runtime Environment).

The JRE does not include a Java compiler (to compile Java source code to bytecode). Arjun, besides the JRE you must have a JDK on your computer somewhere, and you've probably added the bin directory of the JDK to the PATH environment variable.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
The JVM (Java Virtual Machine) is the core of the Java system. It's like the microprocessor in a computer: the engine that executes the bytecode.


This is a common misunderstanding. Mostly, I think, because the name "Virtual Machine" gets associated with what "virutal machine" means in other software/computer areas. Also, the term "machine" is a bit misleading, especially when applied to a specification.

There is only one JVM (the specification). Only one.

There are many JRE's that implement the specifications outlined in the JVM. It is the JRE that is the engine that executes Java bytecode in a particular operating system.
[ June 26, 2008: Message edited by: James Clark ]
Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 627
Originally posted by James Clark:


There is a compiler in a JRE that compiles the class files and creates native code specific to the operating system.

The compiler to create class files from Java source files is "javac.exe". This is a separate executable and is not part of a JRE.



Um.. James. Sorry but I am little confused. Does the JRE have a compiler or not?

Thanks.
Jimmy Clark
Ranch Hand

Joined: Apr 16, 2008
Posts: 2187
Um.. James. Sorry but I am little confused. Does the JRE have a compiler or not?


There is no compiler for creating class files in a JRE. What Jesper Young states about your environment is accurate.

However, there is a compiler in a JRE. This compiler creates the native code that executes on a particular operating system. This compilation occurs at runtime inside the JRE.
[ June 26, 2008: Message edited by: James Clark ]
Bill Shirley
Ranch Hand

Joined: Nov 08, 2007
Posts: 457
This diagram may help.
There is no javac in the JRE proper.
Sometimes people download the JDK, and use the included JRE.


Bill Shirley - bshirley - frazerbilt.com
if (Posts < 30) you.read( JavaRanchFAQ);
Arjun Reddy
Ranch Hand

Joined: Nov 10, 2007
Posts: 627
Um.. I just found why I was able to compile using javac from my JRE'S bin directory. It was because I had the environmental variable set for JDK. I removed it and now I cannot compile the file(using javac).

Thanks for all your replies.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JRE Question
 
Similar Threads
eclipse and javadoc
Unexpected java version in class file
installation of wl6.0 on solaris 2.6
java -version
path variable