can write code for serialization ?
Answer / bharat shivram
import java.io.*;
public class SerializationDemo {
public static void main(String args[]) {
// Object serialization
try {
MyClass object1 = new MyClass("Hello", -7, 2.7e10);
System.out.println("object1: " + object1);
FileOutputStream fos = new FileOutputStream("serial");
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(object1);
oos.flush();
oos.close();
}
catch(Exception e) {
System.out.println("Exception during serialization: " + e);
System.exit(0);
}
Is This Answer Correct ? | 3 Yes | 0 No |
How can u increase the heap size in the memory?
What is the difference in between cpp and java? Can u explain in detail?
How do you check if two strings are equal in java?
Can an integer be null java?
What is sorting algorithm in java?
what is jms? features of jms
What is the best definition for data?
what is difference between prepare stetement and callable starement with example?
How do you use nextline in java?
By what default value is an object reference declared as an instance variable?
Can we compare two strings in java?
What is the requirement of thread in java?