views:

678

answers:

6

We are stuck with Java2SE v1.4 till the end of 2010. That's really nasty, but we can't help it. What options do we have to use some of the new features already now? I can think of several ways like

  • changing the bytecode, e.g. using Retrotranslator or Retroweaver.

  • backport of libraries, e.g. Concurrent Backport, but this does not help for generics.

  • emulation of Java 5 features, e.g. checked Collections, Varargs with helper methods, etc.

  • changing source code by precompilation, stripping all 1.5 stuff before final compilation, e.g. using Declawer can do this.

I am most interested in very positive experience with it in production environments using Weblogic and "real" stuff.

+2  A: 

sourcecode precompilation, stripping all 1.5 stuff before final compilation and deployment. Are there any tools which can do this?

Yes. They're called Retrotranslator or Retroweaver. Apart from Generics (which only exist for the compiler's sake anyway), you cannot simply "strip 1.5 stuff". Enums (and maybe also some other features) have to be replaced with functionally equivalent code. Which is exactly what those tools do.

Michael Borgwardt
Retrotranslator or Retroweaver change the bytecode as listed above. es I agree, not all features will be able to be used. Generics on their own would be a big win already.
Peter Kofler
+2  A: 

You can code with JDK 1.5 features and target JDK 1.4 at compile time. See available Javac options. However, most libraries are now using JDK 1.5 code, so you'll be stuck with old libs.

I may be mistaken, but targeting an older source level (1.4 in this case) restricts you to only using the features in that source level. Please correct me if I am wrong. Perhaps we are referring to different settings, could you add more detail to your answer?
James McMahon
I was told so too, but I am not able to make it work. Usually Source=1.5 needs Target=1.5 in Eclipse and for plain Sun's javac in the command line.
Peter Kofler
You can use the flag -target jsr14
A: 

It worth noting that while Java 1.4 has been EOL for some time. Java 5.0 will be EOL Oct 8th, 2009. If anyone is promising you Java 5.0 by 2010, I would ask why?!

Peter Lawrey
Where I work, we're still stuck with 1.4 as well, though the promise is to switch this year. Large companies are way more conservative and reluctant to change working systems than the people who dream up EOL dates at tech companies imagine. Or maybe those people simply know that said companies are also willing to pay good money for extended support contracts.
Michael Borgwardt
-1 because it does not help me. I know that we should upgrade and I am the first person to say so to management.
Peter Kofler
I worked for a company with 65K employees and now for one with 139K employees and they are only just upgrading to Java 6 on all PCs so I know it can be slow, but Java 5.0 has been available for 5 years, and Java 6 for 2.5 years. Java 7 is likely to available by 2010. I don't think working for a big company is a good excuse. If you have a business case for using a supported/current version of Java you should make one.
Peter Lawrey
EOL's are for limiting support, not for stop using. We still regularily deploy on Java 1.4.
Thorbjørn Ravn Andersen
Some people still use Java 1.3. That doesn't make it a good idea.
Peter Lawrey
A: 

To simulate annotations in java 1.4 you can use http://xdoclet.sourceforge.net/xdoclet/index.html

Mercer Traieste
+6  A: 
Peter Kofler
Compiling entire project from scratch for Java 1.4 production should be handled by your build server.
Thorbjørn Ravn Andersen
A: 

write a program currencyconverter that asks the user to inter todays between u.s. dollars and the euro.then the program reads u.s. dollars values and converts each to euro values.stopwhen the user enters q.

chalak h.m
this is hardly related to the question
Peter Kofler