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 modifiers may be used with an inner class that is a member of an outer class in java programming?

538


Can array grow dynamically in java?

529


Why runnable interface is used in java?

578


Explain about strings in java?

624


What are different types of arrays?

539






What is parsing a sentence?

551


What do you mean by flow of struts?

751


Explain yield() method in thread class ?

627


Which is bigger double or float?

537


What are class types in java?

584


If a method is declared as protected, where may the method be accessed?

538


Why is java called the platform independent programming language?

582


What does compareto () do in java?

578


What is the replace tool?

555


23. Storage space in java is of the form Stack Queue Heap List 24. What is java code embedded in a web page known as Applets Servlets scriptlets snippets 25. Which of the following attributes are compulsory with an tag?. code,height & width. 26. What does 'CODEBASE' in an applet tag specify?. Files absolute path.

2063