What does the keyword "transient" mean in Java?

JavaTransient

Java Problem Overview


I saw somewhere


transient private TrackDAO trackDAO;


Java Solutions


Solution 1 - Java

Google is your friend - first hit - also you might first have a look at what serialization is.

> It marks a member variable not to be > serialized when it is persisted to > streams of bytes. When an object is > transferred through the network, the > object needs to be 'serialized'. > Serialization converts the object > state to serial bytes. Those bytes are > sent over the network and the object > is recreated from those bytes. Member > variables marked by the java transient > keyword are not transferred, they are > lost intentionally.

Example from there, slightly modified (thanks @pgras):

public class Foo implements Serializable
 {
   private String saveMe;
   private transient String dontSaveMe;
   private transient String password;
   //...
 }

Solution 2 - Java

Transient variables in Java are never serialized.

Solution 3 - Java

It means that trackDAO should not be serialized.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser562350View Question on Stackoverflow
Solution 1 - JavaschnaaderView Answer on Stackoverflow
Solution 2 - JavaDeepakView Answer on Stackoverflow
Solution 3 - JavaErikView Answer on Stackoverflow