Before Transient you should know about Serialization
Serialization is process of making the object's state persistent which means that the state of the object is converted into a stream of bytes and will be stored in a file. we can use deserialization to transform to object's state from bytes.we should implement the serializable interface with our class.
transient keyword is used in serialization. If you define any data member as transient, it will not be serialized.
Let's take an example, I have declared a class as Student, it has three data members id, name and age. If you serialize the object, all the values will be serialized but I don't want to serialize one value, e.g. age then we can declare the age data member as transient.
Syntax :
class student {
public transient int id;
}
The id value will be 0 when you serialize the student object and store it in a .ser file.
Answer is Yes, you can define as static and final. The compiler won't complain.
final transient: You can use it if you are declaring non-static constants [1] in your class.
public transient final double PI = 3.14159;
However, if you define some arbitrary objects as final transient for e.g.
public transient final Map<String,Integer> dictionary = loadDictionary();
Then, during de-serialization, the object will have these members as null. Also, it is impossible to reinitialize these values elsewhere because these members are declared as final.
static transient: This could be useful, if you are using a non-standard serializer that also serializes static variables. Otherwise, this is a superfluous statement and you could just use "static".
static final transient: Just take the union of point 1 and 2 above and it will hold for this case.
Static variables are not serialized ( atleast with standard serializers ) so there is no sense marking a variable static as well as transient.
Marking final variable as transient will disable its participation in serialization or deserialization. Final has no relevance with transient in terms of serialization.