nfm
nfm

Reputation: 20667

Am I asking for trouble if I start using Java 7 standard libraries?

I'm writing a program that needs to watch for file system events on multiple platforms. Java 7 includes a new standard library, WatchService, that acts as an abstraction for the different types of filesystem event handlers (inotify, FSEvents, FileSystemWatcher etc).

Is it the case that code compiled with the Java 7 compiler needs a Java 7 JVM to run it?

If so, will I have all sorts of problems with client machines that don't have JVM 7 installed/available for that platform (older OSXs, Windows XP etc)?

Upvotes: 3

Views: 671

Answers (4)

Ken Bloom
Ken Bloom

Reputation: 58770

No, you will not have all sorts of problems running code compiled for Java 7 on a Java 6 VM. You will only have one sort of problem: the code will refuse to run because on a Java 6 VM, because the Java 6 VM will recognize that the version number in the class files is higher than anything the Java 6 VM knows about. You'll get a single, easily diagnosed error.

Your customers won't be able to use the code, but at least you won't be trying to identify the cause of subtle problems.

Upvotes: 1

Stephen C
Stephen C

Reputation: 718708

Is it the case that code compiled with the Java 7 compiler needs a Java 7 JVM to run it?

Yes.

You would be able to use a Java 7 compiler to compile with -target 6.0, but that won't help if the code depends on Java 7 - specific class libraries ... as yours apparently does.

If so, will I have all sorts of problems with client machines that don't have JVM 7 installed/available for that platform (older OSXs, Windows XP etc)?

Yes. That is certainly the case on the "installed" front. If your code depends on Java 7, the best option is to get your customers to install a Java 7 JVM to run it. (It is a simple matter to install multiple versions of Java side-by-side, and there's a good chance that other Java apps will run fine with a Java 7 JVM.)

On the "available" front, we won't know for sure which platforms will be supported until Oracle actually releases Java 7. If there are significant platforms that are not supported, there is a good chance that either:

  • someone will port OpenJDK 7 to the platform, or
  • a 3rd-party vendor (e.g. IBM) will support it in their Java 7 offering.

(But I wouldn't bet on anyone supporting Windows pre-XP, and old versions of OSX are doubtful, IMO.)


My advice would be not to "jump" to Java 7 ... yet ... if supporting old platforms is an important requirement.

Upvotes: 5

Buhake Sindi
Buhake Sindi

Reputation: 89169

Java 7 compiler will compile code from JDK 7 and lower but JDK 6 and lower can't compile code that's using objects/classes from JDK 7.

Is it the case that code compiled with the Java 7 compiler needs a Java 7 JVM to run it?

Yes!!!!

If so, will I have all sorts of problems with client machines that don't have JVM 7 installed/available for that platform (older OSXs, Windows XP etc)?

Yes, as the class version numbers will be higher than the required version numbers needed by the JVM of Java 6 and lower. The client will have to be notified to upgrade their JVM to Java 7.

Upvotes: 1

Mike Samuel
Mike Samuel

Reputation: 120486

Yes and no, Java 7 versions the java bytecode specification. You can compile to an older version of the bytecode using the -target flag, but to use java 7 core libraries, you will need to have a java 7 distro.

There is a project underway to provide java 7 for OS X. I've used it and it worked pretty well for me. Binary Java 7 for Mac

Upvotes: 2

Related Questions