GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

GeekInterview.com  >  Interview Questions  >  J2EE  >  Core Java
Go To First  |  Previous Question  |  Next Question 
 Core Java  |  Question 458 of 493    Print  
Transient and Volatile.
What is the difference between Transient and Volatile. Does volatile variable is serialized and synchronised.


  
Total Answers and Comments: 6 Last Update: June 17, 2008     Asked by: sha_kr2001 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: sampra
 
transient var cant serilizabe
volatile varibale can be changed




Above answer was rated as good by the following members:
interviewprep9, phdsong
January 02, 2008 09:33:20   #1  
rahultiwari8aug Member Since: January 2008   Contribution: 3    

RE: Transient and Volatile.
transient and volatile both are used to define non -serializable members of any class.means if we want to convert an object into byte stream and write into file we serialize the class but if any variable or method which we dont want to serialize,we can specify them by above.note---VOLATILE is used with variable andTRANSIENT is  used with methods. 
 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 2Overall Rating: -2    
January 03, 2008 06:41:29   #2  
sha_kr2001 Member Since: December 2007   Contribution: 7    

RE: Transient and Volatile.
Thanks for your answer.But according to u if Volatile is not serialized then how it can be used for Shared variable.Thant means how the values of volatile var can be modified....
 
Is this answer useful? Yes | No
January 06, 2008 12:34:43   #3  
rahultiwari8aug Member Since: January 2008   Contribution: 3    

RE: Transient and Volatile.
Volatile is assigned with variable when we synchronze that variable in multi threading environment.It also indicate to have a master copy of it ,that is keep an updated value of this variable.
 Transient we use when we want to serialize and object and that object keeps any thread or socket or any other type of member present in that object,then we have to specify them transient so that JVM does not try to serialize them otherwise error will be thrown.

 
Is this answer useful? Yes | NoAnswer is useful 0   Answer is not useful 1Overall Rating: -1    
February 11, 2008 06:25:14   #4  
sampra Member Since: February 2008   Contribution: 279    

RE: Transient and Volatile.
transient var cant serilizabe
volatile varibale can be changed



 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    
June 16, 2008 15:55:14   #5  
interviewprep9 Member Since: June 2008   Contribution: 10    

RE: Transient and Volatile.
Both are used for only intsnace variables.
 
Is this answer useful? Yes | No
June 17, 2008 01:30:24   #6  
atmarammuduli Member Since: December 2007   Contribution: 8    

RE: Transient and Volatile.
Volatile:
Threads dont cache method copy of  Volatile instance variables. Each time when the var is used the thread gets latest copy.

Transient:
instance var not serialized ever. After deserialization its value is null(object) or zero(primitive type).


 
Is this answer useful? Yes | NoAnswer is useful 1   Answer is not useful 0Overall Rating: +1    


 
Go To Top


 Sponsored Links

 




About Us  |   Privacy Policy  |   Terms and Conditions  |   Contact  |   Site Map  |   Add Question  |   Propose Category  |   RSS Feeds  |   Articles Sitemap  |   Site Updates  |   Add Resource

Copyright © 2005 - 2008 GeekInterview.com. All Rights Reserved
Page copy protected against web site content infringement by Copyscape