JavaChallenge39

Govinda Raj
wolfie/JavaChallenge
2 min readSep 19, 2021

--

Try to solve the challenge by yourself first.

We know that finally block always gets executed unless you are not exiting from the code. So, the answer will be false . But how the compiler will make sure that the return statement of the try block is not running instead finally block one will execute. Let’s see the byte-code —

At the compile-time, the compiler is smartly converting the code into byte code which will help the JVM to execute the code without any ambiguity. Here, return false; will be executed but still the finally block will also be executed and it has empty body so it will not do anything. Let’s try some other code —

The compiled code(byte-code) —

Here the compiler will not be able to do any optimization and the JVM will run the code as normal. Try couple of more combinations such as —

You understanding will be more clear.

--

--

Govinda Raj
wolfie/JavaChallenge

Senior Software Developer. Tech Enthusiast and love coding. My portfolio: https://govinda-raj.github.io/