7

I am using Java 1.7 in my code, now i want to replace JAVA 1.7 to JAVA 1.8.Is Java 1.8 compatible to Java 1.7. ? Will it work as it before. i mean, all new features of Java 1.8 can be used in the existing piece of code?

Darshan Patel
  • 3,176
  • 6
  • 26
  • 49
Tarun Chaudhary
  • 1,046
  • 2
  • 12
  • 20
  • 4
    Java 8 isn't officially released yet, so you could argue no one can know 100% for sure yet. – David Jan 28 '14 at 09:53
  • No. If you use JDK1.8 specific features those aren't going to work on a 1.7 JRE/JDK. If you don't use any specific Java8 features and compile to 1.7 it should still will work. – M. Deinum Jan 28 '14 at 09:53
  • AFAIK Java tends to keep a scrupulous retro-compatibility, so yes. You should be fine. – Averroes Jan 28 '14 at 09:53
  • deprecated methods will be removed in java8 so in your project if you have used any deprecated methods then your project will not work in java8 – SpringLearner Jan 28 '14 at 09:55
  • 2
    @JqueryLearner Really? Do you have a source for that? – Kayaman Jan 28 '14 at 09:56
  • @Kayaman Deprecated methods means this http://stackoverflow.com/questions/2941900/is-it-wrong-to-use-deprecated-methods-or-classes-in-java – SpringLearner Jan 28 '14 at 09:58
  • 1
    @Kayaman `Thread#stop` will be removed---not its declaration, but its implementation. I don't know of any other examples, though. – Marko Topolnik Jan 28 '14 at 09:58
  • @david99world exactly official version is not released yet so far, but the new features known to all. – Tarun Chaudhary Jan 28 '14 at 10:01
  • @MarkoTopolnik - do you have a source for that? (The latest Java 8 EA documentation doesn't mention it ... in the obvious place.) – Stephen C Jan 28 '14 at 10:06
  • 2
    @StephenC Only the `Thread#stop(Throwable)` overload has been removed. Reference: http://cs.oswego.edu/pipermail/concurrency-interest/2013-July/011514.html – Marko Topolnik Jan 28 '14 at 10:10

2 Answers2

10

The existing piece of code will (ipso facto) not be using any new features of Java 8. If you have a piece of code which works1 on Java version v, it will also work on all other versions v' > v. That is the long-standing promise of the Java platform.


1 By "works" I mean "works as specified, using non-deprecated official JDK APIs".

Marko Topolnik
  • 195,646
  • 29
  • 319
  • 436
  • As long as your code only depends on public APIs and the Java platform specification, e.g. playing with Unsafe or relying on implementation details like string interning is not covered by that promise. – Pyranja Jan 28 '14 at 09:59
  • Not all software is this way. For a prominent example, the GATK which is a genome-analysis toolkit developed by the Broad Institute. It is only compatible with java 1.7, and will throw exceptions if the Java version is 1.8. – carbocation May 27 '14 at 18:19
  • 1
    @carbocation The reason may well be that it uses deprecated and/or proprietary APIs which are not part of the JavaSE public API. – Marko Topolnik May 28 '14 at 07:50
-3

It depends.

Your question is a little unclear. "Will it work as before" and "All new features of Java 8 can be used in the existing piece of code" seem mutually exclusive.

If you are using a Lambda Expression (Java 8 feature) you will not be able to compile using JDK7. Conversely if you are compiling using JDK7 you will not be able to use any of the new features in JDK8.

TL;DR: If you have to ask, it probably won't.

Mikkel Løkke
  • 3,710
  • 23
  • 37