There are Java debuggers that let you step through the code. I use the one in IntelliJ to set a breakpoint and proceed one line at a time, which works well. There's a free equivalent in Eclipse, but I don't have much experience.
It's also easier to follow the code flow visually if you indent it correctly.