Amazon Interview Question for Software Engineer / Developers


Country: United States




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

Suppose a variable 'x' is being used by thread1 and thread2. Now thread1 applies some algorithm which uses 'x' and the algorithm requires that the value of the variable 'x' can not change unless changed by some operation in the algorithm(which is usually the case) , but in reality the value of 'x' can get changed by an operation in thread2. So in this case 'volatile' keyword is helpful, it will specify that the value of the variable 'x' can get changed automatically, so it will prevent any such algorithms that assume that 'x' can't change unless changed on purpose.

- cheeseburger February 09, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

I am not actually sure....But consider an eg where one variable is used by various resources.volatile is use to when that variable is declared and value of variabke is changed by different threads.

- brion leon February 09, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

Volatile keyword in Java is used as an indicator to Java compiler and Thread that do not cache value of this variable and always read it from main memory. So if you want to share any variable in which read and write operation is atomic by implementation e.g. read and write in int or boolean variable you can declare them as volatile variable.

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

general meaning in programming language (c/c++) of volatile keyword is that a value can be modified with other processes.
Thus, compiler should not be optimized.

- peter February 13, 2013 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

docs.oracle.com/javase/tutorial/essential/concurrency/atomic.html

- Anonymous February 22, 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