• Post Reply Bookmark Topic Watch Topic
  • New Topic

Serializable - transient variable  RSS feed

 
Pranay Karmakar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I've a piece of code which has a transient variable.

After de-Serialization I want to get back the value of that transient variable. Can anyone please tell me the way.

Thanks in advance!


CODE:

 
Patricia Samuel
Ranch Hand
Posts: 300
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to Javaranch . Please use code tag to paste the code on the forum.

As per my knowledge on Serialization, I don't think you can get back the value of transient variable. You use transient for this purpose only when you don't want to persist the value of those variables. and in your case password is a protected thing and should not be sent over the network.

Please clear for what purpose you need password value back.
 
Rob Spoor
Sheriff
Posts: 21135
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to store the password in some way to be able to restore it. Otherwise it will be thrown away, never to be seen again. You could encrypt it before writing it, thereby disallowing people to read it if they cannot decrypt it themselves. You can use the readObject and writeObject methods:
Now all you need to do is encrypt and decrypt your password; do a search in the Java in General forum for hints.

Oh, and please use code tags. You see how much better my code looks with them. You can edit your post to add them.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Prime wrote:Oh, and please use code tags. You see how much better my code looks with them. You can edit your post to add them.
Since he's new, I shall change the tags to code tags to show him how much better it looks
 
Pranay Karmakar
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks to all of you. You guys are really friendly.


@Rob: These are the two methods what I was searching for. Many Many Thanks!

@Campbell and @Patricia: Thanks for the 'code tag'. Its really awesome, I'll use it in my next post.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!