Tutorial :Java Swing 1.6 to 1.5



Question:

Is it possible to port a UI developed using Swing in Java 1.6 to Java 1.5 without rewriting all again?


Solution:1

Just to elaborate on what duffymo said:

Java is designed to be backward compatible. I.e. if you write something in 1.5 you can run it in 1.6. Of course there are limits to that (e.g. new reserved words like assert break it) but in general it works fine.

If you go the other way, it's a bit more dangerous. You certainly won't need to rewrite all your code, but you might have used features only available since 1.6. Such features can be new classes or new methods of existing classes.

Another thing is the binary code level. You can set your compiler running 1.6 to create code for 1.5 or even 1.4.

But beware, that your 1.6 compiler most certainly compiles against a 1.6 rt.jar. That means you won't notice missing classes or methods until you actually run or compile your code with 1.5.

Setting the compliance level only means that the 1.5 JRE will understand the code, not that all "default" classes are available.

I don't have any experience with 1.6 specifics, but i think while 1.5 added a lot of new language features (that are not all compatible with 1.4), 1.6 was more of a maintenance release.


Solution:2

If you've only used features that are common between the two, I'd say yes. It should be backwards compatible. The moment you add JDK 6 specific features you have to take those out.


Solution:3

Since Swing didn't change much in the last ten years, you should not run into many problems. Java 6 also hasn't many new features over Java 5 (mostly internal cleanup).

I suggest to just try to compile your app with Java 5 and run it. It might work out of the box.


Solution:4

If you want to assure your code runs in a 1.5 environment, set your IDE to to build against the 1.5 JDK, that way you won't inadvertently use any of the new API.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »