0

While creating jars, if I create two jars of the same source code but each one in different jre version, will there be a difference in the jars created (i.e. will they function the same)?? please help

Pete
  • 57,112
  • 28
  • 117
  • 166
J Developer
  • 31
  • 1
  • 1
  • 4

2 Answers2

0

Yes they should. Make sure jre versions are compatible with your code.

Rahul Yadav
  • 1,503
  • 8
  • 11
  • just to make my question some what clear, say i create a jar using the jre version 1.6 and other using 1.8 but of the same source code, and if i try to make use of the jar created in 1.8 and run it on 1.6 jre, would it cause some problem? – J Developer Sep 15 '15 at 07:15
  • It should run since it will have backward compatibility but if you try to run jar created in 1.6 on jre 1.8 then there should be compatibility issue like major minor version. – Rahul Yadav Sep 15 '15 at 07:19
  • You have confused backward compatibility... It means a jar created on JDK 1.6 will run on JRE 1.8... Not the other way round... And you create jars with JDK, not JRE by the way... – Codebender Sep 15 '15 at 07:27
  • @Codebender Yeah sorry for the confusion.....and I meant JDK1.6 and not jre. Code compiled in jdk 1.6 should run on jre1.8 but code compiled with jdk 1.8 might face some major minor issue when trying to run on jre1.6. – Rahul Yadav Sep 15 '15 at 07:32
0

As previously mentioned, a jre can can execute code compiled by on a JDK having the same or an earlier version (ex: JRE 1.8 can execute code compiled on 1.6 JDK).

Note that you can specify a target version when you compile your sources so you can make it compatible with a previous version of JRE. Use the -targetoption of javac for this. You can also use the -sourceoption to specify the version with which your source code is compatible; it will imply a target version.

Have a look on Oracle's documentation.

C.Champagne
  • 5,381
  • 2
  • 23
  • 35