Lab #1: Fooling around with objects and Pointers The purpose of this lab is to increase your familiarity with GJDB and to get better intuitions about pointers. 1. Use the 'gmake' command ("Compile" in the Tools menu in Emacs) to compile the Objects class. 2. In a shell, run the resulting program with the command java Objects 3 1 4 1 5 just to see what it is supposed to do. 3. Now use the 'gjdb Objects' command ("Java Debugger" in the Emacs Tools menu) to run gjdb on the compiled program. 4. First, run the program as before with the gjdb command [-] run 3 1 4 1 5 (the [-] is the prompt) to make sure you get the same behavior as before. 5. Place a breakpoint at the line in Objects.java with the comment "Break #1 here". To do this, left-click on the desired line and then use the "Set Breakpoint" item in the Debug menu in Emacs, or use the C-x SPC (that's Control-x spacebar) key sequence in Emacs. (If you make a mistake, type the 'delete' command to the *gud-... window and try again) 6. Run the program again with just [-] run (It should remember the arguments from last time; if not, you can re-enter them). 7. Look at the items of the list L using the following commands (after the main[0] prompts). Try to anticipate what each will print first, and be sure to understand the result in any case: p L.head p L.tail p L.tail.head p L.tail.tail.head p L p/1 L p/1 L.tail p/2 L.tail p/1 L.tail.tail 8. You can call functions from within gjdb as well. Try the following commands: p Objects.printList(L) p printList(L) call printList(L) p L call L 9. Assignments are valid expressions. Try the following sequence. As usual, try to anticipate what will happen before typing the commands. p Q = L.tail.tail call printList (Q) p Q.head += 1 call printList (L) 10. Figure out what to type to gjdb to remove the third and fourth items (4 and 1) from L. It will have the form p something = something 11. Having done step 10, use printList to look at the lists pointed to by L and by Q (again, try to figure out the answer before typing). 12. Find a command that restores the list pointed to by L to what it was before step 10. It will again have the form p something = something 13. Now find a command to delete the 1, 5 items at the end of list L, and again use printList on L and Q. 14. Can you restore the list pointed by L to its previous condition? Can you do it without using 'new'? -------------------------------------------------- ARRAYS: [NOTE: Unfortunately, there is a bug somewhere in GJDB or in Sun software that makes it impossible (I think) to call functions from GJDB with array arguments, so you can't call printArr directly from GJDB. Sorry about that. You can still use 'p' (print), and 'p/1' and 'p/2' to print arrays, fortunately.] 15. Examine the output from running java Arrays and try to understand why it comes out as it does. 16. Run gjdb on Arrays, after arranging for it to stop at the line that says STOP HERE. 17. When the program is stopped at the breakpoint, type the commands p M3 p/1 M3 p/2 M3 p M3[0] p/1 M3[0] p M3[1][2] to see what it looks like. 18. Compare the output of p/1 M1 p/1 M3 Why does it explain the difference in output between the last calls to printArr(M1) and printArr(M3)? 19. Remove the comment marks from the last three lines of main. Replace the "?"s and the ... as needed so that the result of printing M4 is [ [ 4 5 6 ] [ 2 3 ] [ 1 ] [ 2 3 ] [ 4 5 6 ] ] 20. Replace the body of the conifer method so that it does what the comment says to do (at the moment, its answer is only correct if n is 3). Add statements to main to test that your solution works for any n. 21. Check off your solutions to 19 and 20 with your TA. 22. Explain to your TA why the commented-out lines near the beginning of main will cause errors. Before you leave the lab, make SURE that there are no mysteries in this assignment! You should understand how all of the functions work.