Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

A question about JRE, and JDK

 
Yucca Nel
Ranch Hand
Posts: 147
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I never understood this completely. If i code an application using JDK 6+ and I use a eclusive to JDK 6+ class then would a user be able to run it with JRE5? IOW is the JDK version tied to the JRE? If the answer is no then would a proper exception(runtime) for a nimbus LookAndFeel be to advise the user to check their JRE version or try upgrade it?
 
Cristian Senchiu
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yucca Nel wrote:I never understood this completely. If i code an application using JDK 6+ and I use a eclusive to JDK 6+ class then would a user be able to run it with JRE5? IOW is the JDK version tied to the JRE? If the answer is no then would a proper exception(runtime) for a nimbus LookAndFeel be to advise the user to check their JRE version or try upgrade it?

No he will not be able to run the code, because, yes, they are connected. Generally, the version you use to run a code should be at least equal to the version you compiled with (if you don't use any specific target when compiling). Otherwise you'll get an unsupported class version exception (checked through the major.minor versions of your compiled class(es)...).
If user's environment allows an upgrade, that should be the way. You can have more than one JRE versions install, so you could install the newest version and use it with you app and leave the rest of the user's system as it is...
 
vaibhav mishra
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for instance JDK is JRE + Developer tools bundled together, JRE contains the Java runtime, on the other hand JDK contains Java runtime with some developer tools, like Debugger, a compiler and other stuff, so there versions are definitely tied together
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15628
46
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is like this:

If you compile a class with JDK version N, then you need JRE version N or newer to run it. So, a class file compiled with JDK 6 will normally not run on JRE 5 or older - but a class file compiled with JDK 5 will run on JRE 6.

When you compile your class, you can specify a command line switch to produce a class file that it compatible with a certain JRE version, for example:

javac -target 5 MyProgram.java

This will create a class file that is compatible with JRE 5. However, this does not mean that it will run on JRE 5 - if you have used classes from the standard API that are new in Java 6, it will still not run on JRE 5. The "-target" switch only makes sure that the class file version is compatible with the JRE version that you specify.

See the javac tool documentation for details on the "-target" switch.

If you are required to make class files that run on JRE 5, then the safest option is to use JDK 5.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic