Learn Java Tutorial for Beginners, Part 50: Serialization

preview_player
Показать описание
In this video by Quordnet Academy for the series Learn Java Tutorial for Beginners how to use Serialization have been discussed.
If you would like to discover even more about java programming tutorial or the java complete course I advise you to check out the playlist :

Serialization and Deserialization in Java
Serialization
Serializable Interface
Example of Serialization
Example of Deserialization
Serialization with Inheritance
Externalizable interface
Serialization and static data member
Serialization in Java is a mechanism of writing the state of an object into a byte-stream. It is mainly used in Hibernate, RMI, JPA, EJB and JMS technologies.

The reverse operation of serialization is called deserialization where byte-stream is converted into an object. The serialization and deserialization process is platform-independent, it means you can serialize an object in a platform and deserialize in different platform.

For serializing the object, we call the writeObject() method ObjectOutputStream, and for deserialization we call the readObject() method of ObjectInputStream class.

We must have to implement the Serializable interface for serializing the object.

Advantages of Java Serialization
It is mainly used to travel object's state on the network (which is known as marshaling).

java serialization
Serializable is a marker interface (has no data member and method). It is used to "mark" Java classes so that the objects of these classes may get a certain capability. The Cloneable and Remote are also marker interfaces.

It must be implemented by the class whose object you want to persist.

Let's see the example given below:

public class Student implements Serializable{
int id;
String name;
public Student(int id, String name) {
}
}
In the above example, Student class implements Serializable interface. Now its objects can be converted into stream.


ObjectOutputStream class

Constructor
1) public ObjectOutputStream(OutputStream out) throws IOException {} creates an ObjectOutputStream that writes to the specified OutputStream.
Important Methods
Method Description
1) public final void writeObject(Object obj) throws IOException {} writes the specified object to the ObjectOutputStream.
2) public void flush() throws IOException {} flushes the current output stream.
3) public void close() throws IOException {} closes the current output stream.
ObjectInputStream class
An ObjectInputStream deserializes objects and primitive data written using an ObjectOutputStream.

Constructor
1) public ObjectInputStream(InputStream in) throws IOException {} creates an ObjectInputStream that reads from the specified InputStream.
Important Methods
Method Description
1) public final Object readObject() throws IOException, ClassNotFoundException{} reads an object from the input stream.
2) public void close() throws IOException {} closes ObjectInputStream.
Example of Java Serialization

Possibly if you have doubt comment below and let me understand what else I can help you with information in java.This playlist is a full fledged java programming for beginners and java tutorial for beginners which is given above.
Please share with your friends the video to assist other people looking for java programming tutorial or object oriented programming java .
To never miss an update from or channel hit the subscribe button first and if already subscribe hit the bell icon.
1.Follow us on INSTAGRAM for Interesting posts
2.Follow us on LINKEDIN for interesting content on different aspects
3.Don't forget to like our FACEBOOK to get the most out of it
4.Follow us on twitter to get a mix of all
5.If you want to get us on TUMBLR please then click on the link given below
6.Do join our OFFICIAL Telegram for notes of different things
7.For get job update regularly both private and government do join this telegram channel
#quordnetacademy, #java_tutorial_series, #javatutorialseries
Рекомендации по теме
join shbcf.ru