Slashdot Mirror


Using Java 5 Features in Older JDKs

BlueVoodoo writes "Java 5 added a number of powerful language features: generics, enumerations, annotations, autoboxing, and the enhanced for loop. Even if you're stuck on JDK 1.4, you can still use generics. Use Java and theory to learn how."

20 of 37 comments (clear)

  1. Retroweaver by Anonymous Coward · · Score: 2, Informative

    Can't get to TFA for some reason, but isn't this the point of Retroweaver?

    1. Re:Retroweaver by Sciros · · Score: 3, Interesting

      Indeed. It is mentioned at the closing of the article.

      Personally I'm a bit frustrated by this being a noteworthy topic... I'm a Java dev and I really wish accomodating pre-java 5 JVMs wasn't ever needed. Reminds me too much of web development.

      --
      I like basketball!!1!
    2. Re:Retroweaver by Anonymous Coward · · Score: 2, Informative

      Uhmmmmmmmmm

      If I understand correctly, Generics are backwards compatible because of how they get compiled. As long as your development machine supports generics, you don't have to worry about them on older JVMs!

      This is about doing the development on older JVMs. This isn't a backwards compatibility issue in Generics themselves as much as a "If you already have backwards compatibility issues, but want X, here's how to do it."

      But I'm inclined to say if you have problems with JVM versions, you're either doing something wrong and funky or you're trying to develop too much on the bleeding edge.

    3. Re:Retroweaver by Sciros · · Score: 2, Informative

      Class dependencies are different depending on the compiler, so there are a few situations where the JVM executing the code makes a difference. Java 5 isn't that new, so it's not even really bleeding-edge stuff.

      --
      I like basketball!!1!
  2. Fun but not massively practical by dintech · · Score: 5, Insightful

    I've worked in a an environment where 1.4 and lower is mandatory. This was down to management believing that 1.5 was too new and 'untested' even though Sun obviously thought it production worthy.

    These kind of people would be very scared if you tried to write code using 1.5, recompile the byte code using some new-ish open source toolkits and then putting it in to production. Then again, you could do it without telling anyone. :)

    1. Re:Fun but not massively practical by Dan+Hayes · · Score: 2, Interesting
      You think that sucks, I have to code to the last MS JVM, which was 1.1.8 I think. A significant proportion of our userbase still uses it sadly - people still running Win98 most likely. It's very annoying... although I did manage to find a bug in JRE 6 within a day of its release which broke a small but not-insignificant proportion of websites serving applets, well done Sun for not spotting that one when testing your new caching system.

      So to add mouse-wheel support to our applet for those actually using a new JVM, I had to jump through a whole bunch of hoops involving reflection to load classes that exist just to implement the MouseWheelEventListener interface and do a callback to the code. Annoying, I had to do a similar thing to get anti-aliasing to work as well.

    2. Re:Fun but not massively practical by alan_dershowitz · · Score: 2, Informative

      Just because it's production-ready for Sun's purposes doesn't mean it's fully tested and supported by your J2EE application server (for example.) If it's not supported, you're on your own if you have a problem. That's why corporations don't switch right away. As far as code is concerned, if it ultimately ends up being targeted for the 1.4 JVM for example, your unit tests should still work, you're not running your server out of spec, and there shouldn't be any problem IMO.

  3. These have been around for years by ghoti · · Score: 4, Informative

    It's great that IBM is writing this, but these tools have been around for years. They basically came out the same time as the final release of Java 1.5 (or "5.0"), when many people realized that it would be tricky to deploy programs that were using the new features. By now, everybody should have updated to 1.5 anyway.

    --
    EagerEyes.org: Visualization and Visual Communication
    1. Re:These have been around for years by hansamurai · · Score: 4, Interesting

      If only everybody has updated to 1.5. The middle tier of our online product where I work is running on 1.4.2 with just a rumbling of upgrading to 1.5. That upgrade probably won't occur for another year for various reasons that I'm not involved in. I think the bigger the company and the bigger the product, the slower the upgrading process is. I think some architects may even be fearful of 1.5, as I just joined a new project that is running on 1.4.2.13, and they started developing that just last November!

      Anyways, Java 5 has some great features but nothing that is absolutely required from my department's point of view. Autoboxing is a nice feature that helps clean up your code, but nothing we can't do now. Same for the new for-each loop. I could go on but this has been discussed to death already. I would rather we just upgrade so we can start taking advantage of the new features and supposed speed increases.

    2. Re:These have been around for years by RevWhite · · Score: 2, Interesting

      I think the bigger the company and the bigger the product, the slower the upgrading process is.
      I agree with the former, at least. I work for a fairly large organization where nothing terribly critical or large is running on Java, but they still won't standardize, so some things run JVM, some run 1.3, some 1.4, and several apps need specific patch levels of 1.3 or 1.4.
      --
      Hey, can I bum a sig?
    3. Re:These have been around for years by iabervon · · Score: 2, Informative

      Generics are really the important feature. Replacing "Map" with "Map>" is really significant for being able to tell what the code is supposed to be doing and making it work correctly and reliably. For that matter, I had a problem with a commercial J2EE implementation back in the 1.3 days that was returning a Map when it was supposed to return a Map, which was not obvious because it was just returning a Map.

      Of course, this depends on figuring out how all your current code actually works, which can be a major undertaking.

    4. Re:These have been around for years by EsbenMoseHansen · · Score: 2, Informative

      Generics are really the important feature. Replacing "Map" with "Map<String, List<MyDetail>>" is really significant for being able to tell what the code is supposed to be doing and making it work correctly and reliably.

      Of course, this depends on figuring out how all your current code actually works, which can be a major undertaking.

      Yep, this is a step in the right direction. Then we just need the rest of the C++ template features, and we might be approaching something that approaches being a nice language. Like not throwing out half the types during runtime... how silly is that? Getting rid of that terrible Collection framework and replacing it with something STL like (improving the STL interface with a Range class) would be a nice bonus. Oh, and I can have a lambda function, too? And operator overloading. And ruby like setters/getters? Multiple inheritance, or at least mixins, too. And if it could actually make coffee..?

      Man, Java

      is just so damn LIMITING!

      Yes, I love that quote. Describes so much software I dislike :D

      --
      Religion is regarded by the common people as true, by the wise as false, and by rulers as useful.
  4. the bleeding obvious... pointed out... by bitbucketeer · · Score: 5, Insightful

    Java 1.6 is out now. 1.5 is so, like, last year.

    1. Re:the bleeding obvious... pointed out... by Zonk+(troll) · · Score: 4, Informative

      Java 1.5 was released 09/29/2004, so it's over two years old. 1.6 was release 12/12/2006.

      --
      "The Federal Reserve is a fraudulent system."--Lew Rockwell
      End The FED. -
  5. Autoboxing by mccrew · · Score: 3, Funny

    Autoboxing, a bad idea - automated!

    --
    Hey, Windows users, there is no such thing as "forward" slash, there is only slash and backslash.
  6. jsr14 compiler target by Anonymous Coward · · Score: 3, Informative

    You can use the undocumented, unsupported 'jsr14' target in javac to compile 1.4-compatible bytecode from 1.5 source. No need for Retroweaver or other tools:
    javac -source 1.5 -target jsr14

    1. Re:jsr14 compiler target by caseih · · Score: 2, Informative

      If you'll read the article, you'll find that this is mentioned. In fact Retroweaver was around before this undocumented switch, and supports the same things plus a few additional features like the for-each loop, autoboxing, string concatenation, and enumerations. So you'll get a bit more mileage out of Retroweaver than just plain old -target jsr14.

  7. Retroweaver has more features than reported by xlv · · Score: 5, Informative

    I'm the current maintainer for Retroweaver and the article does not mention all the Retroweaver features:

    Annotations are supported, the concurrent backport is used for the concurrent packages, runtime classes can provide support for new features or replace classes entirely, ...

    I suppose the article is based on the 1.2.5 version and not the beta version(s). I guess I followed the Google model of having a really long beta cycle with a stable product...

    Seeing the possible confusion with the Beta tag, I just decided to release the official 2.0 version earlier today.

    Xavier

  8. Misinformation about Retroweaver by rreyelts · · Score: 3, Interesting

    Disclosure: I'm the Retroweaver author.

    The article seems to miss all of the features that Retroweaver has added over the past year. I think the author may not have been paying attention to the active releases on-going with Retroweaver. For example, Retroweaver supports every feature that the author purports is specific to Retrotranslator.

    I have been spending less of my personal time on Retroweaver over the past year, but Xavier Le Vourch has been doing an excellent job improving Retroweaver over that period.

  9. cldc1.0 by pjt33 · · Score: 2, Informative

    -target cldc1.0
    allows you to produce 1.3-compatible bytecode. It has the CLDC preverifier attributes in, but if you're worried about class file size you can strip them with an optimiser.