Example & Tutorial understanding programming in easy ways.

What is the Difference between volatile and transient keyword in Java?

 1) transient keyword is used along with instance variables to exclude them from serialization process. if a field is transient its value will not be persisted.On the other hand volatile keyword can also be used in variables to indicate compiler and JVM that always read its value from main memory and follow happens-before relationship on visibility of volatile variable among multiple thread.
 2) transient keyword can not be used along with static keyword but volatile can be used along with static.
 3) transient variables are initialized with default value during de-serialization and there assignment or restoration of value has to be handled by application code.

Read More →
R4R Team
R4Rin Top Tutorials are Core Java,Hibernate ,Spring,Sturts.The content on R4R.in website is done by expert team not only with the help of books but along with the strong professional knowledge in all context like coding,designing, marketing,etc!