Use of serialVersionUID

SerialVersionUId play an vital role in the serialization. SerialVersionUId is used for version control of object.Consequence of not specifying serialversionUID is that when you add or modify and field in class then already serialized class will not able to recover because serialVersionUID generated for new class and old serialized object will be different.

Java serialization process relies on correct serialVersionUID for recovering state of serialized object and throw  java.io.InvalidClassException in case of  serialVersionUID mismatch.

The serialVersionUID is a universal version identifier for a Serializable class. Deserialization uses this number to ensure that a loaded class corresponds exactly to a serialized object. If no match is found, then an InvalidClassException is thrown.

Guidelines for serialVersionUID :

* always include it as a field, for example: “private static final long serialVersionUID = 7526472295622776147L; ” include this field even in the first version of the class, as a reminder of its importance
* do not change the value of this field in future versions, unless you are knowingly making changes to the class which will render it incompatible with old serialized objects
* new versions of Serializable classes may or may not be able to read old serialized objects; it depends upon the nature of the change; provide a pointer to Sun’s guidelines for what constitutes a compatible change, as a convenience to future maintainers

In Windows, generate serialVersionUID using the JDK’s graphical tool like so :

* use Control Panel | System | Environment to set the classpath to the correct directory
* run serialver -show from the command line
* point the tool to the class file including the package, for example, finance.stock.Account – without the .class
* (here are the serialver docs for both Win and Unix)

readObject and writeObject :

* readObject implementations always start by calling default methods
* deserialization must be treated as any constructor : validate the object state at the end of deserializing – this implies that readObject should almost always be implemented in Serializable classes, such that this validation is performed.
* deserialization must be treated as any constructor : if constructors make defensive copies for mutable object fields, so must readObject
* when serializing a Collection, store the number of objects in the Collection as well, and use this number to read them back in upon deserialization; avoid tricks using null

Other points :

* use javadoc’s @serial tag to denote Serializable fields
* the .ser extension is conventionally used for files representing serialized objects
* no static or transient fields undergo default serialization
* extendable classes should not be Serializable, unless necessary
* inner classes should rarely, if ever, implement Serializable
* container classes should usually follow the style of Hashtable, which implements Serializable by storing keys and values, as opposed to a large hash table data structure

/**
* Determines if a de-serialized file is compatible with this class.
*
* Maintainers must change this value if and only if the new version
* of this class is not compatible with old versions. See Sun docs
* for * /serialization/spec/version.doc.html> details.
*
* Not necessary to include in first version of the class, but
* included here as a reminder of its importance.
*/
private static final long serialVersionUID = 7526471155622776147L;

[Post New]posted Monday, May 09, 2005 10:44 PM private message
Quote [Up]
*g* as you mention “Java RMI”… it says:

“The downside of using serialVersionUID is that, if a significant change is made (for example, if a field is added to the class definition), the suid will not reflect this difference. This means that the deserialization code might not detect an incompatible version of a class.”

and furtheron suggests to implement readObject & friends and writing a version “manually”.

All this in order to gain performance:

“Setting serialVersionUID is a simple, and often surprisingly noticeable, performance improvement. If you don’t set serialVersionUID, the serialization mechanism has to compute it. This involves going through all the fields and methods and computing a hash. If you set serialVersionUID, on the other hand, the serialization mechanism simply looks up a single value.”

Ref – http://sprasanth.blogspot.com/2009/07/what-is-use-of-setting-serialversionuid.html

Book Review : Ext JS 4 First Look

The folks at Packt asked me to review one of their book on EXTJS 4 If you are interested in buying it (a judgment you may reserve until after you have read the review)

“http://www.packtpub.com/ext-js-4-first-look/book” this is link you can go

Loiane Groner iS a EXT-JS consultant, she is expert in EXT JS. As far as I can recall, I have never met them but I follow her blog http://loianegroner.com regularly

The Packt model is an interesting one. They are an online publishing house who approach subject matter experts and offer them an advance and a good commission for writing a book for them. They have approached me a couple of times but I have turned them down on both occasions simply due to a lack of time. Given the movement towards e-readers and related devices I believe it is a business model most publishers will eventually adopt.

Overview and Structure of the Book

The first thing you will probably notice is the size of the document. This is no brief summary of the new features. This is over 340 pages covering what has changed since EXT JS 3 in EXT JS 4 with a full index in the back. The structure of the book is:

• The usual preliminary bits (About the Authors, Acknowledgement, Table of Contents etc.)
• Chapter 1: What new in EXT JS 4.
• Chapter 2: The new Data package
• Chapter 3: Upgraded Layout
• Chapter 4: Upgraded Charts
• Chapter 5: Upgraded Grid, Tree and Form
• Chapter 6: Ext JS 4 Themes
• Chapter 7: MVC Application Architecture
• Appendix
• Index

I like this structure as it parallels the steps one would take in setting up a EXT JS4. The titles are also plain English e.g. ‘Ext JS 4 First Look’ making it easier to know where to go. To add a bit of a flow to the book, they also put it in the examples,real life scenarios
What is missing is – This book is not for the beginners who are learning EXT JS from scratch. Major feature release.
Ext JS 4 introduces major changes compared to Ext JS 3..You will find lot of changes There is a new data package, new charts, and new, updated layouts. The framework was completely changed from EXT JS 3 for increasing the performance.
This book covering all changes in EXT JS 4 , all new features using coding example with detailed explanation and screenshot of code as well the result too. Book will make you understand the changes in EXT JS 4 with presented examples and using this book you can easily migrate the application from EXT JS 3 to EXT JS 4 application

Chapter 1: What’s New in Ext JS 4

This chapter provides an introduction to all major changes between Ext JS 3 and Ext JS 4. Ext JS 4 presents a vast improvement in all packages; the framework was completely rewritten to boost performance and make learning and configuring easy. This chapter covers all these changes, from class system, to an overview, to the new Sencha platform
Good high-level review to introduce the reader to these completely new features

Chapter 2: The New Data Package

This chapters covers all the changes in the data packageI am amazed to see the Sencha Touch framework for mobile application This chapter introduces the new Model class, associations, proxies, operations, batches, and the new features of the Store class.
What this means is the book lends itself to system architects with a good understanding of the configuration options of the system but not so much to people who are new to either system.

Chapter 3: Upgraded Layouts

This is a great chapter on the awesome work Sencha Team has done on improving the layout. It covers all changes made to the existing layouts, and the new component layout engines, such as dock, toolbar, field, and trigger field layouts. It also covers the changes made to the container layouts, such as fit, border, table, anchor, card, accordion, and so on..
If you are stuck in designing the layout of application then reading this chapter is worth of. 

Chapter 4: Upgraded Charts

I like this chapter after reading this a lot. Chapters presents the new JavaScript-powered Ext JS 4 charts. And what you can expect more the no flash is required anymore. This chapter introduces the new draw package, which is the base package for the new chart package. It also covers how to configure chart axis, legend, customized themes, and Ext JS 4 chart series, such as Bar, Column, Line, Area, Scatter, Pie, Radar, and Gauge.

Chapter 5: Upgraded Grid, Tree, and Form

Again, this is a big topic for one chapter. It mention and demonstrates the upgraded Ext JS Components. Very well explained the more performance and more developer flexibility. Some new features and plugins for Components covered in this chapter are: grid, tree, and forms.

Chapter 6: Ext JS 4 Themes

This is probably one of the best example or step by step way of creating on how developer can customize and create a new theme by using CSS architecture, which uses Sass and Compass.

Chapter 7: MVC Application Architecture

. One nice touch in this chapter how MVC architecture applied or implemented to Ext JS 4 applications. This chapter as with others is designed to give the reader a feel for creating a MVC EXT JS 4 application. Steps by steps instruction given in this chapter. Chapter also includes the structure of EXT JS 4 application project structure and how reader can manage the component, files in EXT project structure.
Appendix A, Ext JS 4 Versus Ext JS 3 Class Names,
It presents a comparison list between Ext JS 3 classes and Ext JS 4 class names. In this new version of Ext JS, the names of some classes have changed, and this list can help you find the new Ext JS 4 class names easily, while migrating an application from Ext JS 3 to Ext JS 4 Beta.

Conclusions

This book is not a comprehensive guide to the learn EXT JS 4 or EXT JS. Rather, it is an introduction to some of the new features of the product, compared to EXT JS 3. .It is good guide if you want to migrate an application from EXT JS 3 to EXT JS 4 or if you want learn ,understand the new feature and advanced topic on EXT JS 4.The way author mentioned he pseudo code with example and detailed description is really good. Features of the product they do cover are covered very well. What I mean by this is their high-level summaries of large topics, such as Layout ,tree and form, cover the essential elements and their treatment of smaller topics, such as EXT JS 4 Theme, MVC Application Architecture topic are some of the best I have seen.

While there is not as much bang for buck as, say, Loiane Groner’s book, the EXT JS 4 developer will not have to filter out a rehash of the version 4 features as this book assumes that knowledge. Where I see this book working is as good migration guide. While those volumes allow the reader to drill down into a specific topic, this book, uniquely, gives a much greater context to the features in question, providing a practical example as an integral part of the narrative