serializing an object

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • dmjpro
    Top Contributor
    • Jan 2007
    • 2476

    #1

    serializing an object

    this is my code .....

    import java.io.*;

    class TestSerializeCl ass implements Serializable
    {
    public TestSerializeCl ass()
    {
    System.out.prin tln("Debasis no argument constructor");
    }
    private void writeObject(Obj ectOutputStream out)
    {
    System.out.prin tln("Debasis write Object");
    }
    private void readObject(Obje ctInputStream in)
    {
    System.out.prin tln("Debasis read Object");
    }
    }

    class TestSerialize
    {
    public static void main(String args[])
    {
    TestSerializeCl ass t = new TestSerializeCl ass();
    }
    }

    when those above two private methods will be called and by whome ...


    actually i don't understand why the serialization of an object is necessary ...

    plz help me out ....

    thanx in advance
  • horace1
    Recognized Expert Top Contributor
    • Nov 2006
    • 1510

    #2
    Serialization involves saving the current state of an object to a stream and restoring an equivalent object from that stream. For example, saving an object to a file and reading it back later or transmitting an object over a network connection from a client to server, etc. Have a read of these tutorials
    http://java.sun.com/developer/technicalArticl es/Programming/serialization/
    http://www.deitel.com/articles/java_tutorials/20050923/IntroductionToO bjectSerializat ion.html

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      thanx for ur reply ....

      i understand but can't i do see the two functions called ....

      plz give me some hints so that i can do it myself ...

      thanx again .....

      Comment

      • abctech
        New Member
        • Dec 2006
        • 157

        #4
        Originally posted by dmjpro
        thanx for ur reply ....

        i understand but can't i do see the two functions called ....

        plz give me some hints so that i can do it myself ...

        thanx again .....
        Hello,

        If you are trying to call the two methods [viz,writeObject () and readObject() ] declared in class- 'TestSerializeC lass' from within the class- 'TestSerialize' you will get an error, can you think why?

        Hint: Look at the access modifiers of those methods.

        Comment

        • hirak1984
          Contributor
          • Jan 2007
          • 316

          #5
          we serialize any object to store it somewhere in the hard disk,and remove fron main memory.

          it is important for large programs because it reduces the overheads of main memorythus the application speed increases.
          this is the most basic idea,I can give.
          the details is quite complex.

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by dmjpro
            this is my code .....

            import java.io.*;

            class TestSerializeCl ass implements Serializable
            {
            public TestSerializeCl ass()
            {
            System.out.prin tln("Debasis no argument constructor");
            }
            private void writeObject(Obj ectOutputStream out)
            {
            System.out.prin tln("Debasis write Object");
            }
            private void readObject(Obje ctInputStream in)
            {
            System.out.prin tln("Debasis read Object");
            }
            }

            class TestSerialize
            {
            public static void main(String args[])
            {
            TestSerializeCl ass t = new TestSerializeCl ass();
            }
            }

            when those above two private methods will be called and by whome ...


            actually i don't understand why the serialization of an object is necessary ...

            plz help me out ....

            thanx in advance
            Guys, please let's not forget about code tags when posting our code.

            Comment

            Working...