 Hello friends, I am Sanjay Gupta. In this video, I am going to demonstrate you objects serialization with the help of a Java program. Before starting, you can click on a link which is available at the bottom right corner of this video if you want to subscribe my YouTube channel. You can download my app Techimage that is available on Google Play. You can connect with me by following these details which are available in front of you. Now, coming onto the topic, here you will be learning how objects serialization can be achieved in Java. With this concept, we can write an object into a file and we can also read it back from the file. For that purpose, I have implemented two Java files. I am explaining the first one. It is importing IO package. Then name of classes account holder and it is implementing an interface that is serializable. So whenever you want to apply object serialization, then you have to implement this interface. Then three attributes name balance and passwords are declared. Then account holder. This is constructor here and be and pass will be receiving three arguments which are assigned into name balance and password. Then show method will display values which are stored inside name balance and password. So this is account holder class. Now second class is serialization demo. In this class, main method is defined which is implementing throws clause. It will throw IO exception and class not found exception and these exceptions will be handled by JVM because I have not implemented try and catch blocks. In this code, then there are some statements which are implemented inside main method. You can see some statements are commented right now. So these statements will not execute. So first statement is creating an object of file output stream FOS name of file is file.txt. This is the file which will be storing the data which we want to write inside the file. Then object output stream object OS is created and it is linked with FOS. So if you want to write something then you have to use OS object which is of object output stream. Then account holder class object A1 is created here three arguments James 10,000 and XYZ are passed. This is name 10,000 is balance and XYZ is password. Then OS dot write object A1 this statement is writing object A1 into this file.txt. Then A2 object is created here name Jackson balance 20,000 and password ABC is passed. Then write object is writing A2 into the file then OS is closed and FOS is closed. These remaining statements which are comment right now will read the data which is stored inside the file. So first time executing the statements which are responsible for writing object into the file. This account holder and serialization demo dot Java classes are stored inside the project that is named as Sanjay. This project is stored in the location computer D drive and practice folder. Here you can see project is available. Here no txt file is created till now. Now I am executing this code. It is executed. Now we can check whether the file is created or not. It is created. I am opening this file. You can't read it because object is stored in binary format. Now if you want to check whether the information is properly stored or not, then you have to read it back. So now I am uncommenting these statements and I am commenting previous statements which stored the data. So here you can see file input stream object is created which is linked with file dot txt. Then for reading an object object input stream class object OIS is created which is linked with FIS. Now OIS is reading the object with read object method and it is typecasted into account holder class and it is stored inside X. Then with the help of X dot show the output will be displayed on console. Then OIS is closed and FIS is closed. Now I am executing this code. Here result will be displayed on console. You can see the output name, balance and password. All values are displayed. It is displaying only first object result that is A1 because I have read only one object. If you want to read multiple objects, you can repeat these statements one by one. Friends, with the help of this example, you might have understood how we can store an object into a file and how we can read it back from the file. Now it is reading password properly. There is a mechanism if you want that password should not store. Then you can use a keyword transient. If you are using transient keyword, then passwords will not be stored inside the file. Now again I am executing this code. Now I will be executing all the statements parallelly. So first data will be written inside the file and then it will be read back from the file so that output can be displayed. You can see the output. This time password is null. It means password is not stored inside the file because I have used the keyword transient. So transient is a spatial keyword which don't store the state of the attribute inside the file. So if you want to protect your passwords, you can use transient keyword while using object serialization. I hope you have understood all the concepts which I have demonstrated in this video. If you want to watch more programming related videos, you can subscribe my YouTube channel. Thank you for watching this video.