Amazon Interview Question for Software Engineer / Developers






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

The finally block always executes when the try block exits. This ensures that the finally block is executed even if an unexpected exception occurs. But finally is useful for more than just exception handling — it allows the programmer to avoid having cleanup code accidentally bypassed by a return, continue, or break. Putting cleanup code in a finally block is always a good practice, even when no exceptions are anticipated.

- deaGle September 27, 2008 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

And I'd love to add: if someone hits computer by a hammer (such as System.exit(0) or OOM or something else like a real hammer! For instance, Amazon EC2 instances frequently freeze... unpredictably, for few minutes... just because of virtualization: single CPU shared by 16 clients...)

- bamba May 10, 2012 | Flag
Comment hidden because of low score. Click to expand.
1
of 1 vote

finally block will execute EVERYTIME EXCEPT.... 1)before finally Block, JVM Shutdowns the existing Program anyhow 2) if there is unhandled exception in finally block. Eg:-System.exit(); .... simple as that
Even a return statement in any try - catch block will not stop the execution of finally block. (Tried and Tested :0 )

- Java~Fool September 01, 2012 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

when there is System.exit() in the try block

- vairaghi December 14, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 votes

If you explicitly invoking exit() static method of System Class inside try block then it will not execute finally block and it will initiate process to shutdown JVM.

- vikasgarg333 June 16, 2014 | Flag
Comment hidden because of low score. Click to expand.
0
of 0 vote

In general, the process is killed somehow or there's an infinite loop.

- Jack December 18, 2007 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If a catch clause invokes System.exit() the finally clause WILL NOT execute.

- tejas June 10, 2009 | Flag Reply
Comment hidden because of low score. Click to expand.
0
of 0 vote

If you explicitly invoking exit(), static method of System Class inside try block then in this case it will not execute finally block and it will initiate process to shutdown JVM.

- vikasgarg333 June 16, 2014 | 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