Jgrasp Tutorials
Total Page:16
File Type:pdf, Size:1020Kb
Tutorials Tutorials for the jGRASP™ 1.8.7 Integrated Development Environment James H. Cross II and Larry A. Barowski Auburn University September 2, 2009 Copyright © 2009 Auburn University All Rights Reserved The Tutorials have been updated with each new major release of jGRASP since their original inclusion in the jGRASP Handbook (Copyright © 2003 Auburn University). James H. Cross II is a professor of computer science and software engineering at Auburn University. Larry A. Barowski is a research associate in computer science and software engineering at Auburn University. Printing Considerations The Tutorials are formatted for 5.5 in. x 8.5 in. pages with a base font of 10 point Times New Roman. This improves on-screen viewing and facilitates booklet printing (four pages per sheet of 8.5 in. x 11 in. paper when printing on both sides). On Adobe Acrobat’s Print dialog, select “Booklet Printing” under Page Scaling. The default Booklet Subset will be Both sides. The Tutorials may also be printed “two pages per sheet” on 8.5 in. x 11 in. paper by selecting “Multiple pages per sheet” under “Page Scaling” on Adobe’s Print dialog. This may yield a slightly smaller overall font than booklet printing. If “Page Scaling” is set to “None” (the default) or “Shrink to printable area”, the Tutorials will be printed “one page per sheet” with the font slightly larger than booklet printing. If “Page Scaling” is set to “Fit printable area”, the Tutorials may be printed “one page per sheet” with the font even larger. Regardless of the pages per sheet or page scaling you select, it is strongly recommended that you print a few test pages before printing a large number of pages. The options on your particular printer may be different from the ones described above. Table of Contents Overview of jGRASP and the Tutorials ....................... 1 1 Installing jGRASP .................................................... 1-1 1.1 The Install Files ...................................................................................... 1-2 1.2 Installing on Windows 95/98/2000/XP/Vista ......................................... 1-2 1.3 Installing on Mac OS X ......................................................................... 1-8 1.4 Installing on Other Systems (including x86 Linux, SPARC Solaris, and NetBSD/i386) ............................................................................................ 1-12 1.5 Compilers ............................................................................................. 1-12 1.6 Setting PATH and CLASSPATH ........................................................ 1-14 1.7 jGRASP Start Up Settings ................................................................... 1-15 1.8 Plug-Ins for jGRASP ........................................................................... 1-16 2 Getting Started ......................................................... 2-1 2.1 Starting jGRASP .................................................................................... 2-2 2.2 Quick Start - Opening a Program, Compiling, and Running.................. 2-3 2.3 Creating a New File ............................................................................... 2-5 2.4 Saving a File .......................................................................................... 2-8 2.5 Building Java Programs - - Recap .......................................................... 2-9 2.6 Interactions (Java only) ........................................................................ 2-10 2.7 Generating a Control Structure Diagram.............................................. 2-12 2.8 Folding a CSD ...................................................................................... 2-14 2.9 Line Numbers ....................................................................................... 2-15 2.10 Compiling a Program – A Few More Details ..................................... 2-15 2.11 Running a Program - Additional Options........................................... 2-18 2.12 Using the Debugger (Java only) ........................................................ 2-19 2.13 Opening a File – Additional Options ................................................. 2-22 2.14 Closing a File ..................................................................................... 2-24 2.15 Exiting jGRASP ................................................................................. 2-25 2.16 Review and Preview of What’s Ahead .............................................. 2-25 2.17 Exercises ............................................................................................ 2-27 3 Getting Started with Objects ................................... 3-1 3.1 Starting jGRASP .................................................................................... 3-2 3.2 Navigating to Our First Example Project ............................................... 3-3 3.3 Opening a Project and UML Window .................................................... 3-4 i 3.4 Compiling and Running the Program from UML Window ................... 3-5 3.5 Exploring the UML Window ................................................................. 3-6 3.6 Viewing the Source Code in the CSD Window ..................................... 3-7 3.7 Exploring the Features of the UML and CSD Windows ........................ 3-8 3.7.1 Viewing the source code for a class .......................................... 3-8 3.7.2 Displaying class information ..................................................... 3-8 3.7.3 Displaying Dependency Information ........................................ 3-8 3.8 Generating Documentation for the Project ............................................. 3-9 3.9 Using the Object Workbench ............................................................... 3-10 3.10 Opening a Viewer Window ................................................................ 3-13 3.11 Invoking a Method ............................................................................. 3-14 3.12 Invoking Methods with Parameters That Are Objects ....................... 3-15 3.13 Invoking Methods on Object Fields ................................................... 3-16 3.14 Showing Categories of Methods ........................................................ 3-17 3.15 Creating Objects from the CSD Window ........................................... 3-18 3.16 Using Interactions .............................................................................. 3-19 3.17 Running the Debugger on Invoked Methods ..................................... 3-21 3.18 Creating an Instance from the Java Class Libraries ........................... 3-21 3.19 Exiting the Workbench ...................................................................... 3-21 3.20 Closing a Project ................................................................................ 3-22 3.21 Exiting jGRASP ................................................................................. 3-22 3.22 Review of Toolbar Buttons ................................................................ 3-23 3.23 Exercises ............................................................................................ 3-24 4 Interactions ............................................................... 4-1 4.1 Starting Interactions ............................................................................... 4-2 4.2 Interactions with Primitives ................................................................... 4-3 4.3 Interactions with Reference Types ......................................................... 4-8 4.4 Interactions with Your Own Classes .................................................... 4-10 4.5 Working with Reference Types – Important Details ............................ 4-10 4.6 Interactions with the Debugger ............................................................ 4-10 5 The Control Structure Diagram (CSD) .................. 5-1 5.1 An Example to Illustrate the CSD .......................................................... 5-2 5.2 CSD Program Components/Units .......................................................... 5-4 5.3 CSD Control Constructs ......................................................................... 5-5 5.4 CSD Templates .................................................................................... 5-10 5.5 Hints on Working with the CSD .......................................................... 5-11 5.6 Reading Source Code with the CSD .................................................... 5-12 5.7 References ............................................................................................ 5-18 ii 6 The Integrated Debugger ......................................... 6-1 6.1 Preparing to Run the Debugger .............................................................. 6-2 6.2 Setting a Breakpoint ............................................................................... 6-3 6.3 Running a Program in Debug Mode ...................................................... 6-3 6.4 Stepping Through a Program – the Debug Buttons ............................... 6-5 6.5 Stepping Through a Program – without Stepping In .............................. 6-7 6.6 Stepping Through a Program – and Stepping In .................................... 6-9 6.7 Opening Object Viewers ...................................................................... 6-11 6.8 Debugging a Program .......................................................................... 6-13 7 Projects .....................................................................