Amazon Interview Question for Software Engineer / Developers


Country: India
Interview Type: In-Person




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

The easiest implementation consists of a private constructor and a field to hold its result, and a static accessor method with a name like getInstance().

The private field can be assigned from within a static initializer block or, more simply, using an initializer. The getInstance( ) method (which must be public) then simply returns this instance:

// File Name: Singleton.java
public class Singleton {

   private static Singleton singleton = new Singleton( );
   
   /* A private Constructor prevents any other 
    * class from instantiating.
    */
   private Singleton(){ }
   
   /* Static 'instance' method */
   public static Singleton getInstance( ) {
      return singleton;
   }
   /* Other methods protected by singleton-ness */
   protected static void demoMethod( ) {
      System.out.println("demoMethod for singleton"); 
   }
}

// File Name: SingletonDemo.java
public class SingletonDemo {
   public static void main(String[] args) {
      Singleton tmp = Singleton.getInstance( );
      tmp.demoMethod( );
   }
}

- Sunil B N May 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

you should also make copy constructor and assignment operator as private ... apart from making constructor as private

- debayan May 02, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hi,
Can you please explain Bridge and Adapter pattern?

- Pratik May 02, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

How can u implement the same in C++. Plz give some idea.

- Anonymous May 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

01 public class MyClass{
02 private static MyClass instance = null;
03
04 private MyClass(){
05 }
06
07 public synchronized static MyClass getInstance(){
08 if ( instance == null ){
09 instance = new MyClass();
10 }
11
12 return instance;
13 }
14 }

- napster May 03, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

{
public class Singleton {
private Singleton(){
System.out.println("I am Singletone - Private constructor");
}
private static class SingletonHolder{
public final static Singleton instance = new Singleton();
}
public static Singleton getInstance()
{
System.out.println("I am Singleton - getInstance()");
return SingletonHolder.instance;

}
}

- Career PB May 04, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

Hi,Please help me how can I prepare for Amdocs written test for BTECH freshers.please mail me complete set of question/answers or how can I proceed for that at sagarr807@gmail.com.
I have only two days left for that.Please help me for the same.Also mail me Networking Interview question/Answers

- sagarr807 May 04, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Using the Synchronized is very costly.

public class Singleton {
private static Singleton uniqueInstance = new Singleton();

private Singleton(){}

public static Singleton getInstance(){
System.out.println(uniqueInstance.hashCode());
return uniqueInstance;
}


}

public class TestSingleton {

public static void main(String[] args) {
Singleton.getInstance();
}

}

- Sujeet May 07, 2013 | 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