what is Serializable...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pjerald
    New Member
    • Oct 2007
    • 77

    #1

    what is Serializable...

    can any one explain what is serializable..
    Thanks,
    P.Jerald
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by pjerald
    can any one explain what is serializable..
    Thanks,
    P.Jerald
    What do the books say?

    Comment

    • heat84
      New Member
      • Nov 2007
      • 118

      #3
      Serializable is an interface in Java which is implemented by classes that will be having code that will read or write an object into bits that can be stored on disk or can be sent over the network. Where exactly do you need clarity?

      Comment

      • pjerald
        New Member
        • Oct 2007
        • 77

        #4
        Originally posted by heat84
        Serializable is an interface in Java which is implemented by classes that will be having code that will read or write an object into bits that can be stored on disk or can be sent over the network. Where exactly do you need clarity?
        Thanks r035198x and heat84, This quote gets me some idea.
        But i don understand the following...

        Serializability of a class is enabled by the class implementing the java.io.Seriali zable interface. Classes that do not implement this interface will not have any of their state serialized or deserialized. All subtypes of a serializable class are themselves serializable. The serialization interface has no methods or fields and serves only to identify the semantics of being serializable.

        Thanks,
        P.Jerald.

        Comment

        • r035198x
          MVP
          • Sep 2006
          • 13225

          #5
          Originally posted by pjerald
          Thanks r035198x and heat84, This quote gets me some idea.
          But i don understand the following...

          Serializability of a class is enabled by the class implementing the java.io.Seriali zable interface. Classes that do not implement this interface will not have any of their state serialized or deserialized. All subtypes of a serializable class are themselves serializable. The serialization interface has no methods or fields and serves only to identify the semantics of being serializable.

          Thanks,
          P.Jerald.
          Objects can be serialized if their classes or super classes were specified as implementing the serializable interface. Which part do you not understand there then?

          Comment

          • pjerald
            New Member
            • Oct 2007
            • 77

            #6
            Actually what i am trying to know the term "serialize" ..

            "Objects are serialized with the ObjectOutputStr eam and they are deserialized with the ObjectInputStre am."

            And what the above says..
            Thanks,
            P.Jerald

            Comment

            • heat84
              New Member
              • Nov 2007
              • 118

              #7
              Originally posted by pjerald
              Actually what i am trying to know the term "serialize" ..

              "Objects are serialized with the ObjectOutputStr eam and they are deserialized with the ObjectInputStre am."

              And what the above says..
              Thanks,
              P.Jerald
              Do you then understand Java IO and how the streams work?

              Comment

              • chaarmann
                Recognized Expert Contributor
                • Nov 2007
                • 785

                #8
                Originally posted by pjerald
                Actually what i am trying to know the term "serialize" ..

                "Objects are serialized with the ObjectOutputStr eam and they are deserialized with the ObjectInputStre am."

                And what the above says..
                Thanks,
                P.Jerald
                "Serializab le" means you can save and load the whole object, for example to a file on a disk, or to a database, with just a single command and without going into its internals.
                "Stream" means, you save or load the data to a disk, to a database or to whatever external device you want. It depends on the type of stream.

                For example you have an object that stands for a company. Inside you have a list of employees and a list of rooms. Each employee is an object that has a name, salary, etc.. Each room consists of a list of furnitures. So you see you have a rather complex object. Without serialization, you must loop through the data of your company object and save all the employees, rooms etc., one by one. And when saving an employee, you must write code to save its name, salary etc.. You would do that in some hundred lines of code. And whenever your structure changes, you have to rewrite your code. But with serialization (that means if all components implement the serialized interface), you can save the whole structure with a single command. You can also read an object with a single command.
                No need anymore to write all these lines of code. If your structure changes, no need to change any single line regarding saving or loading. But there is one drawback: if your structure changes, you cannot read an old object into a new structure. Usually you read in an old object and copy the data over into a new object.

                Comment

                • r035198x
                  MVP
                  • Sep 2006
                  • 13225

                  #9
                  Originally posted by chaarmann
                  "Serializab le" means you can save and load the whole object, for example to a file on a disk, or to a database, with just a single command and without going into its internals.
                  "Stream" means, you save or load the data to a disk, to a database or to whatever external device you want. It depends on the type of stream.

                  For example you have an object that stands for a company. Inside you have a list of employees and a list of rooms. Each employee is an object that has a name, salary, etc.. Each room consists of a list of furnitures. So you see you have a rather complex object. Without serialization, you must loop through the data of your company object and save all the employees, rooms etc., one by one. And when saving an employee, you must write code to save its name, salary etc.. You would do that in some hundred lines of code. And whenever your structure changes, you have to rewrite your code. But with serialization (that means if all components implement the serialized interface), you can save the whole structure with a single command. You can also read an object with a single command.
                  No need anymore to write all these lines of code. If your structure changes, no need to change any single line regarding saving or loading. But there is one drawback: if your structure changes, you cannot read an old object into a new structure. Usually you read in an old object and copy the data over into a new object.
                  Serialization simply means writing an object's state to a squence of bytes (and reading those bytes later into an object).
                  The main benefit is actually that objects can persist in memory even after the program(or VM) terminates.

                  Comment

                  • pjerald
                    New Member
                    • Oct 2007
                    • 77

                    #10
                    Originally posted by r035198x
                    Serialization simply means writing an object's state to a squence of bytes (and reading those bytes later into an object).
                    The main benefit is actually that objects can persist in memory even after the program(or VM) terminates.
                    Thanks, chaarmann,heat8 4 and r035198x. Thanks a lot.
                    regards,
                    P.Jerald.

                    Comment

                    Working...