Correct. It gets executed regardless if an an exception is thrown in the corresponding try block. One thing to note is that if an exception is thrown and not handled within a finally block itself, code after that exception does not get executed. For example, in the following code:

if the doSomeCleanup() method causes an exception (say a NullPointerException), the close() method never gets called. This can sometimes lead to hard to track down bugs.

Generally yes. A finally block's primary purpose is to prevent resource leaks or issues by doing appropriate cleanup. At a higher level, it is used to ensure a piece of code is executed, even if an exception occurs in the corresponding try block.

Just to clarify: When I said the code in a finally block is executed even if an exception occurs in the corresponding try block, that means that the code in a finally block gets executed any time the try block is exited, including if an exception occurs. So if the try block is exited due to a return statement, program flow, a break statement, or an exception, the code in the finally block is executed. I just wanted to make sure that was clear since I may not have worded it the best in my initial reply.