I just want to clear the concept about Java serialization process. It clearly states that it helps to convert the object's state in the sequence of byte, that means it helps to save the object's information into byte formed.
My question is, is Java's Serialization and Deserialization process comparable with network's encryption and decryption process? Here is my simple code:
package com.java;
import java.io.Serializable;
public class employee implements Serializable
{
public String firstName;
public String lastName;
}
Here class employee implements the Serializable interface.and it has two variable firstName and lastName. It is very OK:
package com.java;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
public class SerializaitonClass {
public static void main(String[] args) {
employee emp = new employee();
emp.firstName = "Gary";
emp.lastName = "Michel";
try {
FileOutputStream fileOut = new FileOutputStream("./employee.txt");
ObjectOutputStream out = new ObjectOutputStream(fileOut);
out.writeObject(emp);
out.close();
fileOut.close();
System.out.printf("Serialized data is saved in ./employee.txt file");
}
catch (IOException i) {
i.printStackTrace();
}
}
}
In the class SerializaitonClass,create the employee object and access the instance variable(firstname,lastname) and initilize the value.
When I run this,it creates employee.txt file.
When open this file, I get like that
¬í sr com.java.employeeÜ@<~â™` L firstNamet Ljava/lang/String;L lastNameq ~ xpt Garyt Michel
so it converts the whole object's information into byte format. When I use deserialization then I get desired output.
So, can I compare this process with encryption process in network? Maybe I'm totally wrong, so please help me understand.