Results 1 to 4 of 4

Thread: serialization

  1. #1
    Junior Member
    Join Date
    Dec 2006
    Answers
    1

    serialization

    How to acheive the serialiazation?


  2. #2
    Contributing Member
    Join Date
    Sep 2006
    Answers
    42

    Re: serialization

    Implement the java.io.Serializable interface


  3. #3
    Junior Member
    Join Date
    Nov 2007
    Answers
    7

    Re: serialization

    Make your class to implements java.io.Serializable that menas that we are persisting our class. Remember that static variables, transient variables cannot be serialized.


  4. #4
    Junior Member
    Join Date
    Jun 2007
    Answers
    7

    Re: serialization

    Quote Originally Posted by j_priyaa View Post
    How to acheive the serialiazation?
    Serialization is the concept of saving the state of an Object.
    Suppose I have a singleton class
    public class MySingleton {
    private static final MySingleton INSTANCE =
    new MySingleton();

    private MySingleton() {
    }

    public static final MySingleton getInstance() {
    return INSTANCE;
    }
    }


    If you need to make your Singleton class Serializable, you must provide a readResolve() method:

    /**
    * Ensure Singleton class
    */
    private Object readResolve() throws ObjectStreamException {
    return INSTANCE;
    }
    With the readResolve() method in place, deserialization results in the one (and only one) object -- the same object as produced by calls to the getInstance() method. If you don't provide a readResolve() method, an instance of the object is created each time you deserialize the object.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
About us
Applying for a job can be a stressful and frustrating experience, especially for someone who has never done it before. Considering that you are competing for the position with a at least a dozen other applicants, it is imperative that you thoroughly prepare for the job interview, in order to stand a good chance of getting hired. That's where GeekInterview can help.
Interact