File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes What's ServialVersionUID use for ? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What Watch "What New topic
Author

What's ServialVersionUID use for ?

Ryan Chiu
Greenhorn

Joined: Jun 21, 2005
Posts: 5
When I install new version eclipse 3.1, it found out some codes I wrote before didn't have ServialVersionUID ? It's ask me tho add "use default servial version ID" or "generated serial version ID". It's will create coding like this:
private static final long serialVersionUID = 1L;
or
private static final long serialVersionUID = 6594051617034005804L;
Could anyone tell me, what's ServialVersionUID use for ? and what's difference between default ServialVersionUID and other ?
Thank you so much !
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30506
    
150

Ryan,
Welcome to JavaRanch!

If you have an object that implements the Serializable interface, you should have the serial version uid. In general, you want to have Eclipse generate it for you (not use the default).

See this thread in the IDEs forum for more details.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Ryan Chiu
Greenhorn

Joined: Jun 21, 2005
Posts: 5
dear Jeanne:

Thanks for your response. I have seen the thread.
WOW, so that mean when JVM need use a serializable object, it will calculate this serialVersionUID?(I didn't know that, sorry!).And if I write it in my code, the JVM will use it directly, so it can save the time, and like you say:

"In other words using the serialVersionUID will make your code faster and more uniform across platforms."

Is it right ?

Thank you.
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 30506
    
150

Originally posted by Ryan Chiu:
"In other words using the serialVersionUID will make your code faster and more uniform across platforms."

Is it right ?

Exactly!

This isn't the most common piece of Java knowledge, so it's not a big deal for not knowing it. In fact, it's nice of Eclipse to call it to our attention.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What's ServialVersionUID use for ?