Does the bytecode depend on the version of Java it was created with?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
That depends on three things:
The actual Java versions you are talking about. For instance, a 1.4.0 JVM can run code compiled by a 1.4.2 compiler, but a 1.3.x JVM cannot1.
The compilation flags used. There is a
-targetcompiler flag that tells it to generate code that will run on an older (target) JVM. And the-sourcecompiler flag tells it to only accept the older JVM’s language features. (This approach won’t always work, depending on the Java language features used by your code. But if the code compiles it should work.)The library classes that the class file uses. If it uses library classes that don’t exist in the older class libraries, then it won’t run … unless you can include a JAR that back-ports the classes2. You can avoid this problem by using the
-bootclasspathoption to compile your code against the APIs of the older version of Java.Yes, modulo the points above.
1 – The Java 8 JVMS states this: “Oracle’s Java Virtual Machine implementation in JDK release
1.0.2supports class file format versions45.0through45.3inclusive. JDK releases1.1.*support class file format versions in the range45.0through45.65535inclusive. For k ≥ 2, JDK release1.ksupports class file format versions in the range45.0through44+k.0inclusive.”2 – A backport could be problematic too. For example: 1) Things which depend on native code support would most likely require you to implement that native code support. 2) You would most likely need to put any back-port JAR file onto the bootclasspath when you run the code on the older JVM.