I am a program manager for my company and we have just finished a major release using 1.4.2. Now I have read about the exciting changes in 1.5 and I am wondering what the best way would be to go about migrating the current release of our application to use 1.5 for the next release.
Could you give any advice about this?
Many kind regards,
It ran perfectly after I hacked the 1.5 runtime into Tomcat 4. If anything it seems faster than on 1.4.
Originally posted by Ko Ko Naing:
If the application is working perfectly without the features of JDK 1.5, then you don't need to worry about this... Is there any other features that you want to add to your application from JDK 1.5?
Being able to use 5.0 features, such as generics, enhanced for loop, autoboxing, concurrency classes etc. can greatly simplify code. For ongoing projects, switching to 5.0 makes much sense to me, therefore.
But if you do want to develop things using JDK 1.5, use it when you start to develope another new application...
Not everyone has the luxury of being able to start a new greenfield project every year. The application I'm working on is in development (and in production) for over six years now, and we don't expect it to die in the short future.
Here is a good way to start.
First, compile the code as-is using JDK 5. You will probably get some warnings about "raw types". These warnings relate to the use of classes that have been upgraded to generics in JDK 5. For the moment, ignore those warnings. But, respond to any other warnings or errors (if any). Once the code compiles cleanly (except for the warnings about raw types), test the code just to be sure there are no un-expected side-effects.
For those who are unfamilar with the term "raw-type", here is brief explanation: Because generics is a new feature, it was necessary for J2SE 5 to provide a transition path from old, pre-generics code. Remember, there are millions and millions of lines of pre-generics, legacy code that must remain both functional and compatible with generics. That is, pre-generics code must be able to work with generics, and generic code must be able to work with pre-generic code.
To handle the transition to generics, J2SE 5 allows a generic class to be used without any type arguments. This creates a raw type for the class. This raw type is compatible with legacy code, which has no knowledge of generics. The main drawback to using the raw type is that the type safety of generics is lost. This is why raw types generate compile-time warnings.
Second, respond to the raw-types warnings by adding the generic type parameters required to convert a raw type into a generic type. One of the most common places that you will encounter this issue is when using any part of the Collections Framework. Once your compiles are clean, test the application again.
Third, now you can begin look for places in which explicit boxing can be replaced by autoboxing. This is not necessary, but would bring your code into line with the modern approach.
Fourth, look for "magic numbers" that can be made into an enumeration. Enumerations add significant struture to code that relies on several constants. Keep in mind that Java enumerations are more powerful than enumerations found in other languages because they are class types.
At this point, you can begin to analyze the rest of your code for any other places in which feature such as varargs, the for-each style for, or static important will help add structure.
One last point: I have personally had very little trouble moving code to JDK 5.
Also thank you for the specific advice about what we will encounter when we do start to migrate. That has been enough to boot me into migrating!