Question: I'm stumbled upon understanding java serialization. I have read in many documents and books that static and transient variables cannot be serialized in Java.
 We declare a serialVersionUid as follows.

```
private static final long serialVersionUID = 1L;

```

If a static variable was not serialized then, we often face an exception during the de-serialization process. 

```
java.io.InvalidClassException

```

in which the serialVersionUID from the deserialized object is extracted and compared with the serialVersionUID of the loaded class.

To my knowledge i think that if static variables cannot be serialized. There is no point of that exception. I may be wrong because I'm still learning.

Is it a myth that "Static and transient variables in java cannot be serialized". Please correct me, I'm in a mess about this concept.

Answer: 
1. **Instance Variables:** These variables are serialized, so during deserialization we will get back the serialized state.
2. **Static Variables:** These variables are not serialized, So during deserialization static variable value will loaded from the class.(Current value will be loaded.)
3. **transient Variables:** `transient` variables are not serialized, so during deserialization those variables will be initialized with corresponding default values (ex: for objects `null`, `int` `0`).
4. **Super class variables:** If super class also implemented Serializable interface then those variables will be serialized, otherwise it won't serialize the super class variables. and while deserializing, JVM will run default constructor in super class and populates the default values. Same thing will happen for all superclasses.
`serialVersionUID` is special and is not subject to these rules. There is code within the serialization machinery that specifically handles this field to perform the automatic version checks.