can write code for serialization ?

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

how to prepare for IT Officers Interview in Banks

1498


What are abstract methods in java?

639


What is outofmemoryerror in java?

557


What is set and get methods in java?

533


What is ternary operator?

560






Can a constructor call the constructor of parent class?

528


How do I stop concurrentmodificationexception?

504


What is a package in java? List down various advantages of packages.

745


What is the use of conditional statement?

556


what is meant by abstract class?

644


What is the basic concept of java?

529


Can inner class be public in java?

540


What is an class?

585


What is the difference between the font and fontmetrics classes in java programming?

491


Is null keyword in java?

521