 Hello friends, I am Sanjay Gupta. In this video, I am going to discuss the keyword transient which is used in Java for object serialization. If you want to subscribe my YouTube channel, you can click on the link which is available at the bottom right corner of this video. You can download my app Takimiz that is available on Google Play. You can connect with me by following these details which are available in front of you. So first, I am going to discuss it. Then I will be demonstrating the use of transient keyword. So first point says, often it is desirable to save the state of an object. Such objects are said to be persistent. In Java, the state of an object can be stored using serialization. In the object serialization, all the fields of the object is serialized. But sometimes the value of a field in an object should not be saved in which case the field can be specified as transient in the class declaration. So if you don't want to store values of an object in a particular case, then you can use transient keyword inside the class declaration. This implies that its value should not be saved when objects of the class are written persistent storage. The value of transient field does not save with the objects. So you can declare all the fields of class as transient or you can declare some of the fields as transient. So if you are using any field as password, then it should be transient because you don't want to store passwords of the user inside the database. Now, I am explaining an example. So mostly this transient keyword are used while you are implementing object serialization. It means if you want to store an object into a file, then you don't want to store passwords and some private information of the user. So you can see I have implemented a class account holder which is implementing serializable interface. Here three attributes are declared name, balance and password and password is declared as transient. Then account holder constructor which is receiving three arguments and B and pass which are assigned into name, balance and password. Then show method which is displaying all the values on console. Here serialization demo class is implemented which is first reading values through this object creation. Then assigning or storing those objects into a file with write object method. Then again by reading those objects from the file using read object, the values will be assigned into the objects like here. OIS is reading the object using read object method and the result is assigned into X. Then X dot show is showing the result back on console. This is the program which is based on file handling. Here file output stream and object output stream classes are used to create objects which are writing object into file. And file input stream and object input stream classes are used to create objects which are reading object from the file. Now I am removing this keyword first so that you can understand the difference. I am executing the code. So this code first stored the object into file and then read it back. So you can see James 10,000 and XYZ is stored with the help of this A object and while it is reading through this read object and X is printing it on console. James 10,000 and XYZ all three values are displayed. So I am using transient keyword and again I am executing the same code. You can see name and balance are displayed but password is not displayed. So password is available here. Then write object is writing values of A1. It is writing James and 10,000 but it is not writing XYZ into file. So that while reading the object from the file, X is not receiving any password. That's why it is displaying null value. So friends, if you want to prevent storing values of some fields or attributes into a file, then you can place transient keyword before those variables or fields declaration. And it is important while you are writing an object into a file. So if you are implementing object serialization, then you can use transient keyword. I hope you have understood the use of transient keyword in Java. If you want to watch more programming related videos, you can subscribe my YouTube channel. Thank you for watching this video.