Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


ravurivinodkumar
java
2 Answer(s)      6 years and 5 months ago
Posted in : Java Interview Questions



Advertisement
View Answers

July 24, 2008 at 4:48 PM


Hi friend...


Externalizable interface :

When user use Serializable interface, class is serialized by default but Externalizable interface
provides facility to complete control over serialization process so Externalization is a more advanced
alternative to serialization.
This interface has two methods:
1:- public void writeExternal(ObjectOutput out)
2:- public void readExternal(ObjectInput in)

Every class that usese/implements externalization must implement Externalizable interface and override these methods
and must have a no arguments constructor. These methods are automatically called at the time of serialization
and de-serialization so you can can implement your own serialization-specific operations and have control over what data
to serialize and wat to not.

Example Code :


import java.io.*;

public class MyExternObject implements Externalizable {

int i;
String s;

MyExternObject() {
i = 256;
s = new String("Implementation of interface Externalizable.");
}

public int getI() {
return i;
}

public String getS() {
return s;
}

public void writeExternal(ObjectOutput out) throws
IOException {
out.writeInt(this.i);
out.writeObject(this.s);
}

public void readExternal(ObjectInput in) throws
IOException, ClassNotFoundException {
this.i = in.readInt();
this.s = (String) in.readObject();
}

public static void main(String[] args) throws
IOException, ClassNotFoundException {

MyExternObject externObject = new MyExternObject();
System.out.println(externObject.getS());
System.out.println(externObject.getI());
}
}

Output :
Implementation of interface Externalizable.
256


Thanks..


July 25, 2008 at 12:43 PM




Read for more information,


http://www.roseindia.net/java/


Related Tutorials/Questions & Answers:
java
java  diff bt core java and java
java
java  what is java
Advertisements
Java
Java   Whether Java is pure object oriented Language
java
java  different between java & core java
java
java  explain technologies are used in java now days and structure java
java
java   why iterator in java if we for loop
JAVA
JAVA  how the name came for java language as "JAVA
java
java  what is java reflection
java
java  is java open source
java
what is the size of array in java ?  what is the size of array in java ? what is the mean of finalize in java
java
java   in java does not pointers concept but what is nullpointers in java?   nullpointer is a runtime Exception
java
java  write a java program using filenotfoundexception
Java
Java  how to draw class diagrams in java
java
java   difference between class and interface
java
java  why multiple inheritance is not possible in java
java
java  explain object oriented concept in java
java
java  is java purely object oriented language
Java
Java   Whether Java is Programming Language or it is SOftware
java
java  what are JAVA applications development tools
java
java  how use java method
java
java  send me java interview questions
java
java  write a program in java to acess the email
java
java  Write a java code to print "ABABBABCABABBA
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  why to set classpath in java
java
java  give a simple example for inheritance in java
java
java  give a simple example for inheritance in java
Java
Java  how to do java in command prompt
java
java  Does java allows multiline comments
 

 

 

DMCA.com