Should I update aspectJ when migrating from java 6 to 8? - java

My AspectJ version is still on 1.6.8 running on a Java 6 Project.
Suppose I migrate to Java 8.
Should I update the AspectJ version? Is it mandatory?
If yes, are there things I have to be aware of?

This question was flagged as a duplicate before, but I voted to re-open it because the other question was about AspectJ Maven Plugin compatibility with Java 8 and the answers there do not explain anything explicitly in order to answer this question.
AspectJ 1.6.x was published for Java 6, just as AspectJ 1.7.x was for Java 7, 1.8.x for Java 8, 1.9.x for Java 9-13 at the date of writing this.
Having said that, you should consider the following:
If you would just use the Java 8 compiler but compile your Java 6 code with target 1.6, in theory you could continue using AspectJ 1.6.8 (e.g. runtime) too.
But as soon as you compile with target 1.8 and/or use Java 8 language features, you have to use AspectJ 1.8.x (I recommend the latest version) at least in order to make the AspectJ compiler and weaver understand those language features and the byte code at all.
I would even recommend to use the latest 1.9.x version, it is backward compatible and might have a few bug fixes missing in 1.8.x. But that is an optional choice. I always use the latest AspectJ version even in Java 8.

Related

Java - Write code that older version ignore

I try to write my code compatible with older versions of java, so it will work everywhere.
on the other hand there is very powerful tools in the new version - java 8, and I want use them.
So I'm forced to choose between compatibility or richest code.
And I'm wondering if by any chance I can write some methods in java 8, and somehow prevent the compiler of older version to ignore these methods, so my class is compatible "partially" with older version.
Thanks.
You can write two classes and use some toll like ant, maven or gradle to chose which file use for compiling with concrete Java version.
You can set the java compiler to compile against an older jdk (ie jdk 1.5) even if you use jdk 1.8. see javac source and target options
I think the short and easy answer is no.
See this thread: Can Java 8 code be compiled to run on Java 7 jvm?
You can use the java reflection api to check if methods exist in the jvm the code runs on. This allows you to make your code fail-safe even when a method or class is unavailable in the jvm. Doing this is very cumbersome however and I'm pretty sure it's not what your're looking for.

Can scala code compiled with JDK 7 run on JVM 8?

I have a project using scala for several microservices. We are planning to move to Java 8, but due to the limitation of gradle's Scala plugin and the compatibility between scala and Java 8, those micro services will still be compiled on JDK 7. My question is will they run on JVM 8 without any modification or specific configurtion?
Scala 2.11 which is just released is not yet compatible with Java 8 bytecode. However JVM 8 is backward compatible, so as long as you are still compiling your Scala code on JDK 7 and you just drop it in JVM 8, everything will be working fine.
Might not be applicable to you, but latest Scala only works with JDK 6+, so nothing lower than JDK 6.
Yes, they will. So will those compiled on Java 6 or 5. I am not sure about earlier versions, but would still expect them to work.

java 1.8 versus java 1.7 Compatibility Issue

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?
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".
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.

Will programs written against "Java 8" JDK be compatible with "Java 7" JREs?

My question is if Java JDK and JREs have to be compatible to run?
I mean: will Java applications written using JDK version 8 in future work with current JRE's?
It is possible to use cross-compilation options when compiling. Do that and it will be possible to compile code with SDK 8 that is compatible with Java 1.1. It won't be very advanced code for 1.1, but it will run.
The short answer is No.
If you develop your application in JDK 8 and run it with JRE 7, you would get an UnsupportedClassVersionError.
This question is two part:
JDK vs JRE
forward / backward compatibility.
JRE is the acronym for Java Runtime Environment. JDK is the acronym for Java Development Kit: a set of tools which you use to develop Java programs. The JDK also contains a full JRE. In general there is no compatibility issue between the two. But you might want to take care not to use libraries which are only available in the JDK (for example code generation or the tools.jar)
Java itself is compiling to bytecode, which is forward compatible. That means you can use bytecode of any Java version and run it with any newer version. The other way around generally doesn't work and is checked by using the class file version ("java.lang.UnsupportedClassVersionError: Test : Unsupported major.minor version 51.0").
Then there are Java libraries, including the core libraries. So far there was never anything removed from them, so they are forward compatible. This is probably going to change with Java 9 where a very small usually unused library functions are removed.
Regarding to backwards compatibility, this is possible by setting the Java compiler to produce Bytecode of an older version. Up until Java 8, the compiler was always able to produce bytecode of the last two major versions as well. However, you might successfully compile a Java 8 source to Java 6, but not be able to run it. That is the case when you use libraries that are only available on a never Java. For such cases there is for example the maven animalsniffer plugin which will verify that when you compile against an older version, you actually only use libraries existing in said version.

AspectJ works with Java 7?

I instaled AspectJ in Eclipse (AJDT), but the specific methods of Java 7 are marked as errors when I use the AspectJ project.
My doubt is if AspectJ works with Java 7 or this is an issue with Eclipse or AJDT.
EDIT: The problem is AJDT that doesn't support AspectJ for Java 7 yet. There is some IDE to AspectJ that supports?
You need AspectJ 1.7.0 M1 (or higher) for Java 7 compatibility. http://www.eclipse.org/aspectj/doc/released/README-170.html
From the aspectJ webpage:
"AspectJ 1.7.0.M1 is now available for download. See the readme for more information. This is our first Java7 compiler based milestone." so it should work. Did you search at all?
You should install the snapshot version of the AspectJ Development Tools (AJDT) from this update site:
http://download.eclipse.org/tools/ajdt/37/dev/update

Categories

Resources