Amazon Interview Question for Software Engineer / Developers






Comment hidden because of low score. Click to expand.
0
of 0 vote

if you serialize a singleton object and subsequently deserialize that object more than once, you will have multiple singleton instances.It beats the purpose and hence.

Regarding cloneable, obvious - it allows the singleton to be cloned -again - not desirable.

- Ji June 02, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I guess Serialization ignores static fields, because they are not part of any particular object state..And in singleton classes, we use a static variable to keep the only instance of the class..So it maybe a problem..

- garry October 04, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Thanks for the details Ji and Garry...Just to summarize..so that it can help others.

Singlton => One instance of a class.

If you make the class implements serializable then there could be more instance of class that gets created during deserialization if called twice or used reset() methods on the stream. Similarly while serializing it can cause problem if serialization chain in broken or reset() is called during serialization.

And as static fields are not part of serialization, and it plays very important role in singleton there could be a problem of loosing the value.

Cloneable => If we call cloneable on the object then it would generate the another object hence returning another instance of a class.

- master January 03, 2010 | Flag Reply


Add a Comment
Name:

Writing Code? Surround your code with {{{ and }}} to preserve whitespace.

Books

is a comprehensive book on getting a job at a top tech company, while focuses on dev interviews and does this for PMs.

Learn More

Videos

CareerCup's interview videos give you a real-life look at technical interviews. In these unscripted videos, watch how other candidates handle tough questions and how the interviewer thinks about their performance.

Learn More

Resume Review

Most engineers make critical mistakes on their resumes -- we can fix your resume with our custom resume review service. And, we use fellow engineers as our resume reviewers, so you can be sure that we "get" what you're saying.

Learn More

Mock Interviews

Our Mock Interviews will be conducted "in character" just like a real interview, and can focus on whatever topics you want. All our interviewers have worked for Microsoft, Google or Amazon, you know you'll get a true-to-life experience.

Learn More