187

I saw somewhere


transient private TrackDAO trackDAO;

P̲̳x͓L̳
  • 3,547
  • 3
  • 28
  • 37

3 Answers3

270

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;
   //...
 }
schnaader
  • 48,121
  • 9
  • 101
  • 135
  • 5
    @windings: in that case you really need to start [working through tutorials](http://download.oracle.com/javase/tutorial/). Those can't be replace by asking questions. `Integer` is not a keyword, it's a class. – Joachim Sauer Mar 09 '11 at 12:38
  • 231
    The great irony is that this is now the first hit on google. So ... – Richard Rast Sep 27 '16 at 20:06
  • 1
    Is the developer implementing the serializable class responsible for making sure the transient member is excluded in serialization or is Java somehow doing that? – b15 Feb 16 '19 at 16:28
32

Transient variables in Java are never serialized.

Boyan Kushlev
  • 1,003
  • 1
  • 15
  • 34
Deepak
  • 2,074
  • 8
  • 34
  • 48
10

It means that trackDAO should not be serialized.

Erik
  • 84,860
  • 12
  • 192
  • 185
  • 2
    This is the @Transient annotation, not the keyword. – Marcos Vasconcelos Mar 09 '11 at 12:15
  • 4
    @Marcos: what are you talking about? Both the question and the answer are about the `transient` keyword. – Joachim Sauer Mar 09 '11 at 12:16
  • 1
    transient variables are never serialized in java – Deepak Mar 09 '11 at 12:17
  • @Joachim Sauer Actually, I make a mess, I confused with the volatile keyword, @Transient and 'transient' do the same things. – Marcos Vasconcelos Mar 09 '11 at 14:14
  • 15
    @Marcos: no. I assume you're talking about `javax.persistence.Transient`. In that case it does a *similar* thing than the `transient` keyword. The **important** difference, however is that the `transient` keyword applies to serialization, while the `@Transient` annotation applies to persisting an object using JPA. – Joachim Sauer Mar 09 '11 at 14:17