Hi.
I'm a beginner to Java programming and I'm having a hard time grasping how the activation stack works.
I need help drawing the activation stack for this program:
1 public class Q2 { 2 public static void main(String[] args) { 3 String inputStr; 4 int input = 8; 5 6 System.out.print("Input: "); 7 inputStr = StdIn.readLine(); 8 try { 9 input = Integer.parseInt(inputStr); 10 } catch (NumberFormatException ex) { 11 } 12 a(input); 13 return; 14 } 15 16 17 static void a(int limit) { 18 int[] array; 19 int size = 10; 20 21 array = new int[size]; 22 for (int i=0; i<=limit; i++) { 23 array[i] = 3*i; 24 } 25 } 26 }
When the program is given an input of 20, it crashes with this report:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10 at Q2.a(Q2.java:23) at Q2.main(Q2.java:12)
I need to draw the activation stack as it exists at the moment of the crash. Indicate the name
and value of every variable in each activation record. If the variable is an object
reference, indicate that fact and draw the object’s value(s) off to the side of the
stack (since object values are stored in the heap, not the stack).
Thanks.