• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JRE Question

 
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Jimmy Clark
Ranch Hand
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 629
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 2187
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Ranch Hand
Posts: 457
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This diagram may help.
There is no javac in the JRE proper.
Sometimes people download the JDK, and use the included JRE.
 
Arjun Reddy
Ranch Hand
Posts: 629
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic