GeeCON Prague 2014*
The moose likes Features new in Java 7 and the fly likes byte code compatibility with 6 ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Features new in Java 7
Bookmark "byte code compatibility with 6 ?" Watch "byte code compatibility with 6 ?" New topic
Author

byte code compatibility with 6 ?

Jan Goyvaerts
Ranch Hand

Joined: Feb 08, 2011
Posts: 32
Is it possible to use JDK7's features (say Coin) and yet compile for JDK6 ?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39076
    
  23
Don’t know. Is Coin available in Java6? Can you add it to your classpath as a .jar?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39076
    
  23
It might say in the book we are offering how to add features to the classpath for older versions of Java™.
Jan Goyvaerts
Ranch Hand

Joined: Feb 08, 2011
Posts: 32
Is Coin provided as a library in JDK7 ?

I'd rather expect the language changes to be a matter of byte code.
Richard Reese
author
Ranch Hand

Joined: Jul 13, 2011
Posts: 84
    
    5

Java 7 features (COIN) are not available in Java 6. If you want to use the COIN features you have to use Java 7.


Richard Reese
Java 8 New Features: A Practical Heads-Up Guide
Jan Goyvaerts
Ranch Hand

Joined: Feb 08, 2011
Posts: 32
Richard Reese wrote:Java 7 features (COIN) are not available in Java 6. If you want to use the COIN features you have to use Java 7.


I mean of course to write source code with JDK7 - but - to compile it for version 6. The JDK6 JVM's are only used for runtime. As such the developers benefit from JDK7's features and the users don't need to upgrade to JDK7 yet.

Would that work ?
Raymond Tong
Ranch Hand

Joined: Aug 15, 2010
Posts: 230
    
    2

Jan Goyvaerts wrote:
Richard Reese wrote:Java 7 features (COIN) are not available in Java 6. If you want to use the COIN features you have to use Java 7.


I mean of course to write source code with JDK7 - but - to compile it for version 6. The JDK6 JVM's are only used for runtime. As such the developers benefit from JDK7's features and the users don't need to upgrade to JDK7 yet.

Would that work ?

If you use some new features in Java7 but run on JVM6, that would fail. (e.g. Fork/Join)
Because these new features require library which available in Java7+

But if you are using new syntax in Java7, that should be fine. (I have not tried)
(i.e. Improved literal, Diamond Operator, String in Switch)
http://www.java-n-me.com/2012/01/java-7-project-coin-decompiled-part-ii.html
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14194
    
  20

No, you cannot use Project Coin features and compile byte code that is compatible with Java 6.

Project Coin is a set of small changes to the Java programming language itself. It's not available as a library - these are changes to the programming language itself. You can't put that in a library.

If you compile with the -target 1.6 switch in Java 7, it will not allow you to use the new Project Coin language features.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
 
GeeCON Prague 2014
 
subject: byte code compatibility with 6 ?