Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I have a old application written using Java 7. It runs fine in a Java 8 JRE. I do not plan on rewriting any of the code to make use of Java 8 features. Is there any technical benefit to upgrading the compiled code to the latest Java 8 JDK?

To be clear, the code is currently compiled with Java 7 and already running with the latest Java 8 JRE. It should already benefit from the Java 8 runtime improvements. This question is whether any benefits would be gained by compiling with version 8 and running with Java 8 compiled byte code.


Also, I am not concerned with non-technical benefits such as developer productivity. I think those are important but not the point of this question. I am asking for the sake of production code that has NO development team. It is purely in maintenance mode.

share|improve this question
2  
Just to be clear. The code already runs with the latest 1.8 JRE and therefore has all of the latest Java 8 bug fixes and runtime performance improvements (to my knowledge). – g8torPaul 20 hours ago
4  
This is a question probably more about bytecode being outputted by the compiler. Maybe make that a bit more clear in your question. – M Platvoet 20 hours ago
2  
So improved developer productivity is not relevant here? – Mick Mnemonic 20 hours ago
5  
How can "I do not plan on rewriting any of the code" be not clear I can't believe. – eldo 20 hours ago
3  
This may be somewhat related : stackoverflow.com/questions/21732290/… – Berger 20 hours ago

If I understand the question correctly, you want to know if the bytecode produced by javac will be "better" in java 8 than in java 7.

The answer is probably not, they constantly fix bugs in the compiler and that sometimes leads to more efficient bytecode. But you will not see any significant speedup from these fixes for Java 8 as far as I can see, the changelog only lists 2 major changes between versions.

The oracle website is terrible and I can't seem to get a list of bugfixes related to javac between versions, but here is a non exhaustive one from OpenJDK. A majority of the ones I can manage to find are fixing errors. So by updating to Java 8, there is a chance it wont compile anymore due to javac more correctly following the JLS and there will be very little to no "improvements" to the bytecode.

share|improve this answer
1  
Thanks, I have reviewed some of the list on OpenJDK and nothing really stands out there except that it appears they have improved the performance of javac. I agree that it is next to impossible to do a reasonable search of fixes/features between version of Java on Oracles website. The format of the release notes for each version isn't even consistent. My gut tells me that there is no technical benefit to compiling with JDK 8 vs JDK 7. – g8torPaul 15 hours ago
    
@g8torPaul unless you are going to use features only available in Java 8, e.g. lamdbas/streams – Peter Lawrey 1 hour ago

The main benefit is that Java 8 has the latest bug fixes where as Java 7 isn't being publicly updated.

Also if you are going to run code on an Java 8 JVM, you may as well have just one version of Java installed.

Java 8 might be faster, and it has better support for new features like G1. However, it might be slower for your use case so the only way to know is to test it.

Is there any technical benefit to upgrading the compiled code to the latest Java 8 JDK?

If you are asking whether there is any benefit in re-compiling Java 7 code in a Java 8 compiler, the answer is; almost nothing.

The only subtle difference is that there have been minor differences to the Java API, so there might be very subtle differences the Java 8 compiler might find that the Java 7

Other minor differences are the magic number at the start of the file, possibly the order of the constant pool. The byte code is basically the same, even the support for invokedynamic which was added for lambdas existed in Java 7 but just wasn't used that way.

share|improve this answer
7  
Correct me if I'm wrong, but OP asks about recompiling the code with Java 8, whereas your answer is about whether to use Java 8 for executing it? – tobias_k 20 hours ago
4  
I am currently running under the latest Java 1.8 JRE. All of the bug fixes and internal Java code would be provided by the JRE. I don't think this addresses my question. – g8torPaul 20 hours ago
9  
This simply does not answer the question. If it's "almost nothing" please clarify what the difference is. Otherwise it's just speculating – M Platvoet 20 hours ago
1  
@Peter Lawrey, You say that ".. the answer is; almost nothing". Do we have any evidence to support that? BTW, I would tend to agree with you. – g8torPaul 19 hours ago
2  
@g8torPaul Java 8 is designed to be backward compatible with Java 7 and if you are not using any of the features of Java 8, it should produce almost exactly the same byte code. – Peter Lawrey 19 hours ago

I would do for at least these facts.

1) HashMap internals (it is faster under jdk-8)

2) Lots of bugs fixed that might be transparent for you (runtime optimizations) that will make your code faster and better without you actually doing anything.

3) G1 Garbage Collector

EDIT

From a technical point of view this sounds more like something to do with Ahead of Time Compilation or something that a compiler might improve by analyzing the code more. As far as I know such things are not done in java 8 compiler.

From a developer point of view - there are plenty. Increased productivity is the most important one for me.

EDIT 2

I know only two points that matches your second query:

–parameters

to preserve the method parameter names.

-profile

Called Compact Profile Option for a smaller footprint.

share|improve this answer
20  
Wouldn't just running under Java 8 already give these benefits though? The real question seems to be, "can I write something in Java 8 that works better than the Java 7 equivalent". – Jorn Vernee 20 hours ago
8  
I am currently running under the latest Java 1.8 JRE. All of the bug fixes and internal Java code would be provided by the JRE. The Garbage collector is also part of the JRE. I don't think this addresses my question. – g8torPaul 20 hours ago
7  
@JornVernee OPs explicitly said that he does not want to rewrite anything, so the question, as I understand it, is more like "can the Java 8 compiler do any tricks the Java 7 compiler can't do" – tobias_k 20 hours ago
1  
@JornVernee The Question is, if code written in Java 7 and compiled in Java 8 executes better then the code compiled in Java 7 – EarlGrey 20 hours ago
6  
Does not answer the question and merely speculates it hasn't improved. – M Platvoet 19 hours ago

It could help by creating awareness.

When you switch to Java8, you might find additional warnings being emitted by javac. Example: type inference has been greatly improved with Java8. And that could eliminate the need for @SuppressWarnings annotations that you have in your code base today (and when the annotation is no longer required, the compiler warns about it being unused).

So, even when you don't intend to modify your code base today, switching to Java8 could tell you about such things. Increasing your knowledge can help in making informed decisions.

On the other hand:

  • I saw some questions here about (rare) situations where Java8 refused to compile Java7 code. So, switching to Java8 also carries a (minimal) risk of running into that kind of problem.
  • And: even when you don't intend to touch your code base today, there is a certain chance that you change your mind later on. And then, when not paying attention, you might exploit Java8 features. Which could complicate "field updates"; as you now have two versions of your source code to maintain!
  • Then: in case you have customers running the product using a java7 jre; you have to be really careful about the binary fixes you give to them. We have such a setup; and I have wasted time more than once because I accidentally put a single Java8-compiled class onto a Java7-driven test system. That simply can't happen when your dev and test/customer setup is all Java7.

Long story short: there are a few subtle advantages, and certain risks (where the significance of the risks mainly depend on your overall setup).

share|improve this answer

My team just went through the upgrade from Java 7 to Java 8, without changing code. Aside from any potential benefits you are exposing yourself to some risks. Although the tests I refer to are perhaps not well formed we ran into conditions in which the operation of the HashMap class changed. Tests that were expecting certain things in map entry 0 found them in map entry 1. Since it's a map we shouldn't be looking at a specific index, but nonetheless this JUnit code detected the unexpected change in operation. You run the risk of running into unexpected changes to the operation of your code, potentially with no benefit. "If it ain't broke, don't fix it."

share|improve this answer
3  
This seems like bad advice. They are currently running their application with JDK 1.8; so if there are actual behavior changes between JDK 1.7 and JDK 1.8, then they actually should run their tests with JDK 1.8. – ruakh 11 hours ago
2  
Doesn't answer the question, which is about whether or not to recompile. OP is already running with JRE 8. – EJP 10 hours ago

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.