This article on recursion explains it quite well: How recursion works
In your case a sequence of method calls is put on a call stack and then traversed just like you're saying. Everytime we call the function recursively that call is put on top of the call stack:
f(3) -> 2 * f(4)
f(4) -> 1 + f(2)
f(2) -> 1 + f(1)
f(1) -> 1
When this is computed we then get
f(1) = 1
f(2) = 1 + 1 = 2
f(4) = 1 + 2 = 3
f(3) = 2 * 3 = 6
And then we return the value of the last computation. So we don't tell the recursive method to stop, but rather we run the function recursively building up a stack of method calls until we reach a function call that is no longer recursive, in this case f(1). Once we have reached that point we compute the call stack until we reach the first call taking the result from the previous execution with us.
If the input to your method never ends up in a call to f(1) then the recursion will not stop and you will get stuck. Your method will not have that issue, but consider this method:
public static int bad(int i) {
return bad(i + 1);
}
That method will never reach a terminating state and will fill up your call stack until you run out of memory. So it is important to make sure that your function does not cause infinite recursion. Many IDEs will warn you about this.
if (n <= 1) return 1;. So Basically what is happening rn is that everytime you go in either the second "if" statement or the return, you call the same function again, and it will keep doing that until you eventually return 1.