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 does thread synchronization occurs inside a monitor? What levels of synchronization can you apply?

779


What are the advantages of arraylist over arrays?

816


Write a program in java to calculate the difference between the sum of the odd level and even level nodes of a binary tree.

765


What is the difference between overriding & overloading?

774


How can we pass argument to a function by reference instead of pass by value?

840


Which methods cannot be overridden in java?

763


What will happen when using pass by reference in java?

732


What is module in project?

748


What is the difference between array list and vector in java?

743


Give an example of call be reference significance.

817


How do you input a string in java?

762


What is the main use of java?

852


What is boolean false?

753


How many bits is a 64 bit byte?

759


What do heavy weight components mean in java programming?

721