can write code for serialization ?



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

Post New Answer

More Core Java Interview Questions

Is char a data type in java?

0 Answers  


What is unicode?

1 Answers  


How would you format a date in java? I.e. In the ddmmyyy format?

0 Answers  


Explain scope or life time of local variables in java?

0 Answers  


what is difference Between Core Java and advance java

60 Answers   HCL, HP, Sambalpur University, TCS, Vensai Technologies, Wipro,






Is class is a data type?

0 Answers  


How u dubugg ur project?

1 Answers   iFlex,


What are operators and its types?

0 Answers  


What is the main functionality of Prepared Statement?

4 Answers  


What is the difference between serializable and externalizable interface?

0 Answers  


What is difference between next () and nextline () in java?

0 Answers  


write a program to create an arraylist with string(add,remove) operation.and value should be enter through keyboard.

0 Answers   Axcend,


Categories