Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Will compiling for Java 1.5 on Java 1.7 still work?

I've recently moved to Java 7 in one of my projects. I claim that it can run on Java 1.5 simply because there's nothing I depend on that is in Java 6 or 7. However when compiling today I noticed this:

bootstrap class path not set in conjunction with -source 1.5

Google has found little information on this warning. Does this mean that you can't compile to Java 1.5 from Java 1.7?

like image 261
TheLQ Avatar asked Oct 21 '11 23:10

TheLQ


People also ask

Is Java 7 backwards compatible?

The backwards compatibility means that you can run Java 7 program on Java 8 runtime, not the other way around. There are several reasons for that: Bytecode is versioned and JVM checks if it supports the version it finds in . class files.

Can program developed with Java 7 be run on Java 8?

Binary Compatibility Except for the noted incompatibilities, class files built with the Java SE 7 compiler will run correctly in Java SE 8. Class files built with the Java SE 8 compiler will not run on earlier releases of Java SE.

How do I compile a Java program with a specific version?

You can use the -jo compiler command line option in order to specify options to be passed to the Java compiler such as: "-source" and "-target". In order to check the version number in a . class file you can use the javap utility that is distributed with the JDK.


1 Answers

This Oracle blog explains the warning:

http://blogs.oracle.com/darcy/entry/bootclasspath_older_source

The reason is, that if you fail to set rt.jar for the older platform, then:

If the second step is not taken, javac will dutifully use the old language rules combined with new libraries, which can result in class files that do not work on the older platform since references to non-existent methods can get included.

like image 173
paulsm4 Avatar answered Sep 27 '22 17:09

paulsm4