• Post Reply Bookmark Topic Watch Topic
  • New Topic

Sample program about serialization.........

 
Vinney Shanmugam
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi folks..... please give a sample code which explains how to implement serialization and also if there any links to read about this, do paste them.

i just want to implement serializable in a class and return that class's object over the network and see a msg displayed from that object....

Please help me
 
kiran mathew
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.io.Serializable is a marker interface. So just implement the interface on your class. You can also override the readObject and writeObject methods for customization if required.
 
Vinney Shanmugam
Ranch Hand
Posts: 104
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class samp
{
JMXReturnObject jmxobj = new JMXReturnObject("JMX","Reply");
sout.write(jmxobj.toString().getBytes()); // sout is the outputstream.
}

class simp implements
{
private String a;
private String b;
public simp(String a, String b;)
{
this.a = a;
this.b = b;
}
}

will this code work???


}
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The trick about serialization is that you won't need to write the bytes directly.


This will work for any object, as long as:
  • The object implements Serializable, either directly or through one of its ancestors
  • All non-transient* fields are primitives, or Serializable themselves. Contents of arrays or collections must be Serializable as well. Arrays are Serializable by default.

  • If these rules do not hold, you will not be able to serialize the object; any attempt will cause an exception.

    * I mentioned the word transient here, because if that is added to a field's modifiers, that field will not be stored.
     
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!