Amazon Interview Question for Software Engineer / Developers


Country: United States




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

Ref: stackoverflow.com/questions/2423622/volatile-vs-static-in-java

Even if you access a static values through multiple thread each thread can have it's local cached copy! To avoid this you can declare the variable as static volatile and this will force the thread to read each time the global value

- Anonymous March 17, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

so does it mean always use static together with volatile? any case use volatile only?

- zyfo2 March 19, 2013 | Flag
Comment hidden because of low score. Click to expand.
4
of 4 votes

It doesn't mean, use only static volatile (or) volatile..the usage should depend on your requirement.

volatile is only used for visibility among all the threads..if one thread changes the field value, the changed value is reflected to all the threads only if the field is declared volatile.

static, meaning the field is associated with the class, but not the object.
If the field is made static volatile it means that the changes in the "class field" is made visible to all the threads acting on that class (or) all the object instances.

If its not static but only volatile, which means the changes in the "instance field" is made visible to all threads acting on that particular object instance.

- Anonymous March 19, 2013 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 votes

got it. thank you

- zyfo2 March 20, 2013 | Flag


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