Considering this code, can I be absolutely sure that the finally block always executes, no matter what something() is?
try         
        Here's the official words from the Java Language Specification.
14.20.2. Execution of try-finally and try-catch-finally
A
trystatement with afinallyblock is executed by first executing thetryblock. Then there is a choice:
- If execution of the
 tryblock completes normally, [...]- If execution of the
 tryblock completes abruptly because of athrowof a value V, [...]- If execution of the
 tryblock completes abruptly for any other reason R, then thefinallyblock is executed. Then there is a choice:
- If the finally block completes normally, then the
 trystatement completes abruptly for reason R.- If the
 finallyblock completes abruptly for reason S, then thetrystatement completes abruptly for reason S (and reason R is discarded).
The specification for return actually makes this explicit:
JLS 14.17 The return Statement
ReturnStatement: return Expression(opt) ;A
returnstatement with noExpressionattempts to transfer control to the invoker of the method or constructor that contains it.A
returnstatement with anExpressionattempts to transfer control to the invoker of the method that contains it; the value of theExpressionbecomes the value of the method invocation.The preceding descriptions say "attempts to transfer control" rather than just "transfers control" because if there are any
trystatements within the method or constructor whosetryblocks contain thereturnstatement, then anyfinallyclauses of thosetrystatements will be executed, in order, innermost to outermost, before control is transferred to the invoker of the method or constructor. Abrupt completion of afinallyclause can disrupt the transfer of control initiated by areturnstatement.
The finally block is always executed unless there is abnormal program termination, either resulting from a JVM crash or from a call to System.exit(0).
On top of that, any value returned from within the finally block will override the value returned prior to execution of the finally block, so be careful of checking all exit points when using try finally.
Yes it will get called. That's the whole point of having a finally keyword. If jumping out of the try/catch block could just skip the finally block it was the same as putting the System.out.println outside the try/catch.
The Java Language specification describes how try-catch-finally and try-catch blocks work at 14.20.2
In no place it specifies that the finally block is always executed.
But for all cases in which the try-catch-finally and try-finally blocks complete it does specify that before completion finally must be executed.
try {
  CODE inside the try block
}
finally {
  FIN code inside finally block
}
NEXT code executed after the try-finally block (may be in a different method).
The JLS does not guarantee that FIN is executed after CODE. The JLS guarantees that if CODE and NEXT are executed then FIN will always be executed after CODE and before NEXT.
Why doesn't the JLS guarantee that the finally block is always executed after the try block? Because it is impossible. It is unlikely but possible that the JVM will be aborted (kill, crash, power off) just after completing the try block but before execution of the finally block. There is nothing the JLS can do to avoid this.
Thus, any software which for their proper behaviour depends on finally blocks always being executed after their try blocks complete are bugged.
return instructions in the try block are irrelevant to this issue. If execution reaches code after the try-catch-finally it is guaranteed that the finally block will have been executed before, with or without return instructions inside the try block.
No, not always one exception case is// System.exit(0); before the finally block prevents finally to be executed.
  class A {
    public static void main(String args[]){
        DataInputStream cin = new DataInputStream(System.in);
        try{
            int i=Integer.parseInt(cin.readLine());
        }catch(ArithmeticException e){
        }catch(Exception e){
           System.exit(0);//Program terminates before executing finally block
        }finally{
            System.out.println("Won't be executed");
            System.out.println("No error");
        }
    }
}
                                                                        Answer is simple YES.
INPUT:
try{
    int divideByZeroException = 5 / 0;
} catch (Exception e){
    System.out.println("catch");
    return;    // also tried with break; in switch-case, got same output
} finally {
    System.out.println("finally");
}
OUTPUT:
catch
finally