A co-worker and I recently had a discussion about Java versions and the JVM. I use Java 7 but we use Java 6 for our client (while he says that some are still on 5). My immediate thought was, why can't we target those VMs too?The Java VM is somewhat different than a real machine in that it has a bunch of runtime features. Type checking, exception handling, garbage collection, etc. But it's still a virtual machine which has a bytecode. (Which is why we can have things like C to JVM compilers.) So why can't we target older VMs with newer version of Java? Why does the language and the runtime have to be tied together? Besides the obvious performance penalties, it seems like it should be completely possible to compile Java 7 code to the Java 6 JVM. (And considering how little changed from Java 6 to 7, I can't imagine the compiler changes being that extensive.)
Java Compiler and VM Compatibility
java;jvm
I think the main reason is simply that the demand for this feature is not very high, because upgrading to newer JVMs is generally quite painless. And the kind of organizations and people who insist on running outdated JVMs anyway are probably not keen on using the newest language features either.Of course, it's certainly possible - nobody prevents you from writing such a compiler. But the only example I'm aware of that saw widespread use is Retroweaver, which let you use the Java 5 features on 1.4 JVMs. But then, Java 5 has the biggest, most useful new features of any Java version, so there was much more value in having this than with other versions.