Well, of course, there is no difference between them as such at runtime. But you should definitely use the 2nd method to save your code.
Why am I saying this, suppose in the future you need to add a few more lines to the if-else block to expand them. Then, if you have the first method included in your old code, you need to add braces before adding new code. What you do not need to do in the second case.
Thus, it is much easier to add code to the second path in the future than to the first.
In addition, if you are using the first method, you should make input errors such as semi-colon after your if , for example:
if (a > 0); System.out.println("Hello");
So you can see that your Hello will always print. And you can easily remove these errors if you have curly braces attached to your if .
source share