File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes A question about JRE, and JDK Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Beginning Java
Bookmark "A question about JRE, and JDK " Watch "A question about JRE, and JDK " New topic
Author

A question about JRE, and JDK

Yucca Nel
Ranch Hand

Joined: Nov 20, 2008
Posts: 147

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?


SCJP 6.0, SCJD (400/400), SCBCD for JEE 5, SCWCD 1.4 I do videos for development at
http://www.youtube.com/user/thejartender?feature=mhee
I am probably the only developer ever to have had an orange sized brain tumor in my brain while learning development!!
Cristian Senchiu
Ranch Hand

Joined: Feb 08, 2009
Posts: 40
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

Joined: Jun 18, 2008
Posts: 168
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


SCJP
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14193
    
  20

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
 
GeeCON Prague 2014
 
subject: A question about JRE, and JDK