Question: Can somebody suggest any approach to generate unique Id preferably integer for Java classes .I need to have each of my Java classes to have some kind of a unique Id which would be written via a serialization strategy to be used to get back the same class in a distributed set up .

Answer: 
Take a look at the [UUID](https://docs.oracle.com/javase/1.5.0/docs/api/java/util/UUID.html#randomUUID%28%29) class. It has [toString()](https://docs.oracle.com/javase/1.5.0/docs/api/java/util/UUID.html#toString%28%29) function. You could take the hash of that value.
I'n mot sure you can get what you want.

It would be nice to have the entire thing be an automated part of the build process so it sort of "just happens".

It seems the only near constant information available from a Java class to represent a unique class is the full package and class name "canonical path". But if someone renames it or changes the package you are screwed.

To get any shorter ID that is assigned once and persistent will require some sort of persistent registry database loaded at application startup and available to all applications that will be serializing the same classes. You then then look up the actual runtime class from it and assign it to an internal registry. 

It would be nice if in some manner by which a unique ID can be generated when a class without an assigned ID is first created, and an annotation or other field can be added to the source code for the classes in question.