September 15, 2005
Eclipse 3.1, RAD 6.0 and serialVersionUID
"What's that serialVersionUID all about? And do I have to type in that long number?", a student asked.
We were discussing Serialization in the context of JavaBeans yesterday in a J2EE class that I'm teaching here in Canberra. It was one of those moments when I knew I should have been able to provide a good answer there and then but my mind was blank. So I gave the "I'll have to get back to you on that one" answer.
I had some vague recollection about the serialVersionUID (universal version identifier) being important for versioning of JavaBeans. This forum item confirmed my suspicion as well as highlighting the performance hit if serialVersionUID is not declared. If it isn't, each time the class is loaded reflection and hashing is used to generate it.
And with regard to versioning, there may be times when you want to change a class but still enable old versions to be loaded. Declaring a serialVersionUID will allow this. Otherwise an InvalidClassException will result.
The answer to the second question could be: use the serialver tool that comes with the JDK. But when you're working within an IDE like RAD or Eclipse that goes against the grain.
It turns out that in Eclipse 3.1, by default a warning will be issued by the compiler (listed under Potential programming problems in Window --> Preferences --> Java --> Compiler --> Errors/Warnings) if no serialVersionUID exists for a Serializable class. Then a quick fix can be used to easily generate one.
In RAD (based on Eclipse 3.0) all is not lost. The Code Review function allows a similar quick fix to be used to generate the serialVersionUID declaration.
Update (7th October): See this later post for clarification on performance issues.
Posted to Software Development by Keith PittyIs "Code Review" supported in RAD 7.0?
Posted by: J Smith at June 27, 2007 2:23 AMIt looks like the Code Review function is not in RAD 7.0. However, it is based on Eclipse 3.2 so a quick fix can be used to generate a serialVersionUID.
Posted by: Keith at June 27, 2007 11:36 AM
