How to run Java in compatibility mode? - java

Does Java support running in compatibility mode? In other words if we have JDK 8 install on system, can it be configured to run my application on 7 or previous release using the same installation ?
I can give one example like IE-11 can be switch to run as IE 8, 9, or 10 based on the compatibility option.

I agree with the comment of Kayaman.
There are 2 types of incompatibilities that could occur: bytecode changes (some feature supported in 8 and not in 7 - new Java versions tend to be upward compatible - so 8 will be able to run all 7-targeted code) and library changes which is more problematic.
If you have compiled with Java 8 targeting 7+, your bytecode will be compatible with Java 7 JVM, but you have no guarantee that it will run with Java 7 libraries.
Your best bet is then to compile and run with Java 7 - and it will (most probably) run with Java 8.
Then there are other changes that may impact your application (GC performance for instance).

Related

Is Java 8 forward compatible with Java 11?

I'm migrating multiple projects from Java 8 to Java 11 and I was wondering if Java 8 is forward compatible with Java 11.
In other words, is it possible to use artifacts compiled against Java 11 in Java 8 projects?
No, you cannot execute Java 11 bytecode on an older (any older) JVM. This has always been the case. Each new major compiler release has a new bytecode format that won't execute on older runtimes.
You CAN however execute bytecode from an older version on a newer JVM, so executing Java 8 bytecode on a Java 11 runtime is quite possible and you can thus use Java 8 (or older) compiled libraries in Java 11 projects, if the dependency requirements are met.
Do however keep in mind that Java 9+ removed a number of packages from the core libraries that were in there with Java 8, so you may need to supply new dependencies from third parties to replace those. Most notable of those (but certainly not the only ones) are XML parsers.
You can run projects that were compiled for Java 8 in Java 11 runtime.
You can run projects that were compiled for Java 11 in Java 8 runtime if you properly set the --target during compilation to target JDK 8 or less. This will of course also limit the set of features supported in the source code.
Generally, earlier versions of JDK are supported on later runtimes (i.e. Java 11 should run on Java 17), but there are some caveats because some of the features might get deprecated or changed. Always read the release notes and test before you upgrade.

Java JDK 11 Breaking Old Jars/Programs

It is to my understanding that Java JREs are backwards compatible, if you write a program in Java (JDK) 7, it will run with Java (JRE) 8.
I have a couple of programs I developed in Java 8, and have .jar and EXE files that I built when I finished them, and they always ran fine. However, after installing Java JDK 11 (11.0.2), these old .jar files break...
A couple of them still run, but their GUIs have expanded, with buttons and images being bigger than before, and in some cases blurry
One program just doesn't run at all, trying to run it in a console gives an exception: "Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: javax/activation/ActivationDataFlavor"
I understand that this class and some other javax classes have been removed from JDK 11, so from a development standpoint you couldn't use them anymore without a tool such as Maven. But I do not understand why installing JDK 11 has any effect on my old jars, as I didn't install a new JRE, and even if one came with it, it should be backwards compatible?
Too add to this, I use Apache NetBeans 10, it worked fine with Java 8, but after I installed JDK 11, NetBeans 10 still ran but its loading window was big and blurry, and the IDE's images are blurry, and all the text is bigger.
So why is installing JDK 11 having these negative effects on older programs?
Note - I have tried associating the jars/EXEs with javaw.exe from JRE version 8 (201), however, they all still have the same issues.
Java tries to be backward compatible but sometimes breaking changes are necessary to evolve the ecosystem. Until now breaking changes were shipped with major release e.g. Java 9, 10, 11. In your case you are most likely affected by Java 11's JEP 320: Remove the Java EE and CORBA Modules.
Remember that Java 8 was released in 2014. For 5 years Oracle and the Java community provided patches and security fixes for Java 8 but doing this forever is impossible.
The issue you are facing is likely not an incompatiblity w.r.t. the bytecode. It is just a missing class.
Java 11 dropped the support of some old technologies - for example Java Applets. If you run a Java 8 Applet in a Java 11 JDK / JRE you will get a ClassNotFound exception just because Java 11 does not provide the class / jar.
Similarly for JavaFX, which still exists, but is not longer part of the Java Distribution. You have to add it as a separate Jar.
I believe it would be possible to add these classes to a project. Personally I would like to see a port.

Java Runtime Environment deleted after update?

On my machine, yesterday, I had installed and configured 6 java versions:
JRE 6
JRE 7
JRE 8
JDK 6
JDK 7
JDK 8
I believe an update was installed last night and today, both JRE 6 and 7 are missing (in 7, the lib folder is still there, as jars from it might have been locked by running applications).
JDKs are perfectly fine, same is JRE 8.
After checking on a different machine (windows as well), the same thing happened: JRE 7 missing almost completely.
Did any else experience this? If yes, what is the cause? Is it an Oracle "feature" to remove older JREs?
I should mention that we have application which for various reasons need 6 or 7, and cannot be updated to 8 at this time.
Thanks.
Yes, it's a feature. In the Java 6 times it was not, and it ended up in a library hell with dozens of versions of the JRE installed at the same time - something that, in theory, should not be needed as those versions are supposed to be compatible with each other.
As the documentation says:
The Java auto-update mechanism is designed to keep Java users
up-to-date with the latest security fixes. To achieve this goal
Windows and OS X users that rely on Java’s auto-update mechanism will
have their JRE 7 replaced with JRE 8.
...
As we did when JRE 6 was replaced by JRE 7, we have auto-updated users of the older release to the newer version of Java.
If you need to support older environments, you can set your compiler's compliance level. You will not be able to use newer features of the language, but it should run just fine.
You can also keep multiple JDKs installed and use that to test - the JRE comes bundled with it, so you just have to browse to that folder on the command prompt and compile with javac and/or start your app with java.

running different jre versions on the same machine [duplicate]

This question already has answers here:
Multiple Java versions running concurrently under Windows
(10 answers)
Closed 9 years ago.
I was wondering if there would be any implications (slowed performance, crashes and so on),
running a java 1.4 application and a java 1.6 application on the same machine
Different java version are installed in different directories so running 2 java programs with different JRE version will not make any effect other than that you are running 2 processes of java.
So bottom line, there is no problem with that, it will not slow you down.
Also, java 6 has better performance than 1.4 so if you can run both on 6 its usually better.
None, The only problem is you can only have one default JVM. If you have too many versions e.g. hundreds it is likely to be a bit of mess, but it won't slow you down.
It seems that the header does not correspond the question. Running different jre versions on the same machine is not the same as running a java 1.4 application and a java 1.6 application. So I will give 2 answers
Yes you can have 2 different jre installed on your machine.
You can run 1.4 application (classes compiled in Javac 1.4) on JRJ 1.6 but you cannot run 1.6 application (classes compiled in Javac 1.6) on JRE 1.4.
Of course, It will not slow machine. A machine can have multiple JVM on single machine. There will not be any kind of conflict because everything would be in separate folder.
There is only special case in case of multiple JDK/JRE.
Case : - What version will be used by your browser.
For this you can control all the things from java console from control panel in windows.
Yes, you can have multiple JRE installed on the same machine on the same O/S. And you can have one project configured with one version of Java Compiler on your IDE. But remember when you run Higher version of Java compiled code on a JRE having lower version, you might face some issues with the new features and enhancements introduced with the later versions.

What are the pitfalls when upgrading to Java 7

I am switching an enterprise application built on Spring 3.1.0, Hibernate 3.6.0 from Java 6 32bit to Java 7 64 bit.
Has anybody done that? Any problems? Are there any resources on the subject?
Here are the pitfalls I know about:
You might have to upgrade your IDE to be able to enable Java 7 features.
Make sure that command line tools and your IDE use the same Java version. If you're using Maven, for example, look into $HOME/.mavenrc and/or check the environment variable JAVA_HOME
Check the source/target options of the Java compiler.
Java 7 supports generics better than Java 6 so some code will now compile that failed with Java 6
The 64bit version of Java uses a lot more memory than the 32bit version
The first release of Java 7 had a severe bug in the JIT compiler which broke Lucene. Use at least b2 or better.
Java 7 uses the newer JAXB 2.2 instead of 2.1 (the full change on the XML stack is described here). These versions are not compatible on generated code for Boolean getters and setters!

Categories

Resources