Amazon Interview Question for Software Engineer / Developers






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

limitations:
Implementation of serialization and cloneable causes the problem.
In the Distributed computing and in multiple class loader there is a chance of multiple objects getting created.
Subclassing if done, there if not implemented correctly it could cause more problem with multiple objects.

- master January 03, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Reflection can create multiple copies of an object even in the singleton pattern.

- sushbis July 14, 2010 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Overhead due to synchronized access to the getInstance(). In cuncurrent world, we need to make this synchronized to avoid 2 threads creating different instance. However as a side effect, we have the overhead of synchronized everytime its invoked.

- Raj March 05, 2011 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

i) Inheriting a singleton class should be prohibited. Making a singleton class inheritable means any number of child classes can inherit from it creating multiple instances of the singleton class which will obviously violate the principle of singletons.

ii) We will be able to create a copy of the Object by cloning it using the Object’s clone method.. To avoid this, you need to override the Object’s clone method, which throws a CloneNotSupportedException exception:

public Object clone() throws CloneNotSupportedException {
        	throw new CloneNotSupportedException();
       }

iii) If Singleton Class implements the Serializable interface, then instances can be serialized and deserialized. However, if you serialize a singleton object and subsequently deserialize that object more than once, you will have multiple singleton instances. To avoid the above you need to implement readResolve() method.

private Object readResolve() {
				   return INSTANCE;
		}

- hulk March 31, 2014 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

only one object can be created

- Amit April 14, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

Make a class can create only one instance?

- job-searcher May 10, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
-1
of 1 vote

constructors should be private

- Akhil Chityal November 20, 2009 | 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