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

What is java in simple terms?

566


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

761


Difference between final and effectively final ?

640


List the interfaces which extends collection interface?

540


What is boolean strategy?

630






What are the important features of Java 10 release?

513


Can we access instance variables within static methods ?

573


What an i/o filter in java programming?

608


Why singleton pattern is better than creating singleton class with static instance?

540


What is default constructors?

543


What is difference between static and abstract class?

524


Distinguish between a predicate and a function?

575


What is meant by vector class, dictionary class, hash table class, and property class?

687


Does java return by reference?

537


What is int lol?

596