1

When I programme I don't take care if I'm using the features in Java 7 or Java 5. But as far as I think if I use only Java 5 features my complied byte codes should be run also on a JRE version 5. But how can I check if my compiled code will be compatible with JRE v. 5 or even earlier or no.

I'm interested to know the answer of this question more generally for Web and Enterprise applications.

Johnny
  • 1,509
  • 5
  • 25
  • 38
  • 1
    You mean programatically? (or) something like this http://stackoverflow.com/questions/1096148/how-to-check-the-jdk-version-used-to-compile-a-class-file – kosa Nov 21 '13 at 15:09
  • http://stackoverflow.com/questions/1293308/java-api-to-find-out-the-jdk-version-a-class-file-is-compiled-for – Santosh Nov 21 '13 at 15:11
  • I mean when I finish developing a Java Application how can I understand which is the minimum version of Jre that can run my bytecodes (classes all bundled in a jar file) – Johnny Nov 21 '13 at 15:14
  • 1
    As a first step, you could specify `-source 1.5` (see [javac command line arguments](http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html) - you could also use `-target` but as far as I understand -target is managed automatically and tracks -source's setting) but that will not catch issues caused by usage of classes/methods introduced in later JDKs – fvu Nov 21 '13 at 15:15
  • @Nambari those questions are different. But they let me know that it is possible to compile a java programme in compatibility mode. – Johnny Nov 21 '13 at 15:16
  • @fvu so If I develope a Java programme using lamda functions my programme will never be able to run on the Jres earlier than 8.0? – Johnny Nov 21 '13 at 15:19
  • 1
    @Johnny it won't even compile if you use `-source 1.5` – fvu Nov 21 '13 at 15:20
  • 2
    I think README.txt files (or) documentation is the only way you can use to figure out which version it is (if you don't want to run any code & figure out comparability by just looking at WAR/EAR file). In nutshell, if you don't want to run code there is no automagic stuff available. – kosa Nov 21 '13 at 15:20

1 Answers1

1

You can compile your code with a specific version using the -target option

Try compiling with different targets to see which compiles and which doesn't

http://docs.oracle.com/javase/7/docs/technotes/tools/windows/javac.html