Java Serialization Introduction .

What you need to know before this learning.

  • You should have learned and understood everything under Java Basic.
Java Serialization
  • Whenever an java object is to be sent over the network, and moreover if the state of an object is to be saved, java objects need to be serialized.
  • With Serializing we mean to convert a java object to a stream of data. It is also known as a marshalling process.
  • A serialized object contains the information necessary to deserialize or unmarshal, the object.
  • The and classes are used to write and read objects on any type of existing I/O streams.

How to serialize java object to a file:

  • To write a serialized java object to a file, create an from a
    (The data in the file is in a proprietary Java format, so it will be difficult for you to read it)
    // Serialize today’s date to a file. f = new"tmp"); s = new;
    s.writeObject(new Date());
    You will find more details about this here.

How to serialize java object to another Java program:

  • To write a serialized java object to another Java program, retrieve the from a and create the from that.
    (The other Java program will re-create the object when reading it)
    Socket socket = new Socket("someHost", 2201);
    OutputStream OutStream = socket.getOutputStream(); stream = new;
    stream.writeObject(new java.util.Date());

How to serialize java object to a byte array:

  • To write a serialized java object to a byte array, create a and wrap an around it.
    (This array could then be stored in a DBMS) bstream= new; st = new;
    st.writeObject("This is a test string");
    byte[] bytes=bstream.toByteArray();
© 2010 by Finnesand Data. All rights reserved.
This site aims to provide FREE programming training and technics.
Finnesand Data as site owner gives no warranty for the correctness in the pages or source codes.
The risk of using this web-site pages or any program codes from this website is entirely at the individual user.