Take a copy and pencil, start from the first line and use your copy page as the stack or heap and your pencil as a pointer to store values in stack and heap. Now keep on tracing the code. Forexample;
for(int i=0;i<3;i++){
System.out.println(i);
}
First, i must know what for loop do, so i know that it iterates the body until it's condition gets false.
Now i=0 and condition is if 0<3 that is true, it will go to the body, print the i value, increment the i value to 1 and again check the condition 1<3, true again, body will be executed again, i will be incremented and so on.....