Write Java with JDK 1.5 features and run on JRE 1.4

Java code with Java 1.5 features running on Java 1.4 runtime environment is an interesting situation.

Have you being writing your Java code on Java 1.5 (JDK 1.5) with new features like auto boxing, generics and enums? And suddenly realized that your customer's servers are still using Java 1.4 (JRE 1.4)? This is not a surprise since most of the customers are not in a position to take a risk and try the newer versions as they are running live/online businesses. But as professionals in the software development field, we have to move with the latest/stable versions available in the market. That's where the conflict occurs.

Java Now you must deploy your Java 1.5 codes into a 1.4 Java runtime environment (even may be 1.3 or 1.2). Even if the Java code has not used any of the new features of Java 1.5, you still can not run your code in 1.4 JRE as the runtime throws an error saying "java.lang.UnsupportedClassVersionError".

Compile 1.5 codes for 1.4 JVM

Java compiler provides an option to specify the target JVM of the generated classes like 1.5, 1.4, and 1.3 as follows.
public class MyClass {
    public static void main(String args[]) {
        System.out.println("Main Method");
    }
}

Compile with...
javac -source 1.4 -target 1.4 MyClass.java

Even if your JDK is of version 1.5, above command will compile your class so that it can run on a JRE 1.4. But the above option only works if your class does not use any of the new features in Java 1.5 (like auto boxing, enums etc).

Check the following class. Compiling it with "target" option will result in a compile time error.
public class MyClass {
    public static void main(String args[]) {
        Integer count = 1;
        System.out.println("Main Method");
    }
}

Compile with...
javac -source 1.4 -target 1.4 MyClass.java

The compiler error is shown because auto boxing is not supported in 1.4.

This means that we can not use 1.5 features if we are going to run the programs on an older version. So this is not a real solution for our issue.

Can not run/deploy code with new features on 1.4 JVM?

Java retroweaver logo There is an open source free solution to this issue. The tool is named "Retroweaver", and it can generate class files for older JREs using classes with new features of the 1.5 version. This is a nice tool and it supports most of the Java 1.5 features.

Retroweaver site says;
Retroweaver supports most 1.5 features while running on 1.4.
  • generics
  • extended for loops
  • static imports
  • autoboxing/unboxing
  • varargs
  • enumerations
  • annotations

Also this has a good documentation (even though it's not up to date. Don't blame them; they are doing it for free).

This tool can convert .class files of 1.5 version to another older JRE version. Also it has the capability of converting a complete .jar file.

COMMENTS

BLOGGER: 4
Loading...
Name

About,2,Adsense,3,Ant,1,Apache,3,Axis,3,Blogger,1,Books,1,CentOS,2,Chrome,2,CSS,2,Database,3,Earn Online,3,Eclipse,10,Facebook,1,Firefox,10,Gmail,4,GNU/Linux,9,Google,26,GWT,8,Hardware,2,IE,5,Interesting,15,Internet,14,Java,49,Javascript,7,JBoss,1,Jenkins,1,Log4j,2,Me,6,Microsoft,2,Miscellaneous,1,News,11,Opinion,10,OSGi,1,PHP,1,Productivity,3,Programming,36,Puzzle,3,Security,4,Software,41,Sports,9,Spring,2,Story,6,Subversion,3,TDD,4,Tech,2,Tips,1,Tomcat,6,Tutorial,13,Ubuntu,4,Web application,14,Web Design,2,Web services,3,Windows,10,Yahoo,1,Zip,2,
ltr
item
Digizol: Write Java with JDK 1.5 features and run on JRE 1.4
Write Java with JDK 1.5 features and run on JRE 1.4
Java code with Java 1.5 features running on Java 1.4 runtime environment is an interesting situation.
https://3.bp.blogspot.com/-KaUEjxwkaS0/WehOk0kkbVI/AAAAAAAACXc/HS5P0pVdYgM4qHLwhJMjzrubVS8fj5kVgCLcBGAs/s1600/Write%2BJava%2Bwith%2BJDK%2B1.5%2Bfeatures%2Band%2Brun%2Bon%2BJRE%2B1.4%2Bwww.digizol.com.png
https://3.bp.blogspot.com/-KaUEjxwkaS0/WehOk0kkbVI/AAAAAAAACXc/HS5P0pVdYgM4qHLwhJMjzrubVS8fj5kVgCLcBGAs/s72-c/Write%2BJava%2Bwith%2BJDK%2B1.5%2Bfeatures%2Band%2Brun%2Bon%2BJRE%2B1.4%2Bwww.digizol.com.png
Digizol
http://www.digizol.com/2008/08/java-write-jdk-15-run-jre-14-deploy.html
http://www.digizol.com/
http://www.digizol.com/
http://www.digizol.com/2008/08/java-write-jdk-15-run-jre-14-deploy.html
true
7440473
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy