Volatile: In a multithreaded scenario when a shared variable value is modified by Thread1 might not be immediately updated to main memory. When Thread2 reads, it will get the old value. You can avoid this by specifying the variable with volatile modifier. When we specify the variable as volatile, its value will be synchronized with main copy as and when it modified. This solution is not 100 percent accurate. To get accurate results in multi threaded scenario you can use atomic classes.
Transient: This modifier is used when we don't want to serialize the value of the member variable when serializing the object.