jGRASP Tutorial
jGRASP Tutorial
for Java
Maria Litvin
Phillips Academy, Andover, Massachusetts
Gary Litvin
Skylight Publishing
1. Introduction
2. Downloading and Installing jGRASP
3. Creating a Project and Running “Hello World”
4. Bringing Existing Java Files into jGRASP
5. Command-Line Arguments and User Input
6. Running GUI Applications
7. Workspaces
8. Using Jar Files
9. Creating Jar Files
1. Introduction
This document serves as a brief introduction to jGRASP. See a more detailed jGRASP tutorial at their
web site.
jGRASP was developed by the Department of Computer Science and Software Engineering in the Samuel
Ginn College of Engineering at Auburn University. The latest version of jGRASP, as of July 2015, is
Release 2.0.1_05. jGRASP is a free download.
According to www.jgrasp.org,
jGRASP not only enables the user to edit and run Java programs, it can also produce what its developers
call Control Structure Diagrams (CSDs) for Java (and other programming languages). Our primary
concern here is how to use jGRASP as an IDE (Integrated Development Environment) for editing and
running Java programs.
First make sure the Java Development Kit (JDK) is already installed on your computer.
See www.skylit.com/javamethods/faqs/GettingStartedJava.pdf for directions.
Go to www.jgrasp.org and click Download in the left column, then click on the green button that
corresponds to your operating system. Run the downloaded installer file and follow the instructions.
Under Windows, jGRASP will be installed by default in the C:\Program Files\jGRASP folder. The
executable jGRASP file jgrasp.exe will be located in C:\Program Files\jGRASP\bin and a
shortcut to it will be placed on your desktop. (If the shortcut does not show up or is accidentally deleted,
you can always create it by dragging jgrasp.exe to the desktop while holding down Ctrl+Shift or
Alt.)
A novice might want to uncheck “Auto Sync” and uncheck all boxes under “CSD Window Settings”:
GETTING STARTED WITH ECLIPSE FOR JAVA 3
You might want to change the “Look and Feel” setting to match your operating system (for example,
“Windows” for Windows).
Navigate to the folder in which you want to place your new project, and under the Project menu select
New. In the dialog box that pops up enter the project name, for example, “Hello”:
4 GETTING STARTED WITH JGRASP FOR JAVA
Check the “Create new Folder” box so that jGRASP places all project files in a separate
folder (with the same name as the project).
Click Next. jGRASP will come up with another dialog box. It will show that jGRASP has created a file
with the .gpj extension, which describes the project (for example, Hello.gpj) and placed it in the
currently selected folder. If you want to add files to the project right away, check the “Add Files to
Project Now” box. Otherwise, the project will remain empty. Click Create.
To create a new Java file in the project, choose New on the File menu, then Java. Type in the text for
your file in the editor window (or paste it from a different source). For example:
GETTING STARTED WITH ECLIPSE FOR JAVA 5
Choose Save on the File menu (or press Ctrl+S). jGRASP is smart enough to propose the name for a
Java file that matches the name of the class in the file, with the extension .java.
To run a program, make sure its “main” class (the class with the main method) is open in the editor
window and choose Run on the Build menu, or press Ctrl+R, or click the “Run” button on the
toolbar. The console output will appear in the “Messages” pane under the “Run I/O” tab:
6 GETTING STARTED WITH JGRASP FOR JAVA
Or, choose Add Files on the Project menu, navigate to the file(s) you wish to add, and click Add.
Make sure you choose “Copy” on the dialog box that pops up; choosing “Move” will
relocate the original file(s), and choosing “Link” may modify the original file(s).
To open the file in the editor, click on a Java file in the “Browse” or “Project” window. To close a file,
click on the “cross” button in the upper-right corner (or right-click on the corresponding tab and chose
“Close”).
Note that the Generate CSD command on the View menu (or pressing F2) temporarily
changes the indentation step to three spaces when the CSD is removed. Closing and
reopening the window restores the indentation step to two spaces.
GETTING STARTED WITH ECLIPSE FOR JAVA 7
To run a program that takes command-line arguments, check Run Arguments on the Build menu. A
text entry field will appear where you can enter the arguments:
The Greetings2 program prompts the user for input. Predictably the console dialog appears on the
“Messages” window under the Run I/O tab. For example:
8 GETTING STARTED WITH JGRASP FOR JAVA
Click on any Java file to open it in the editor, then press CTRL+R to run it.
You can also click on the “Run” button on the “Open Projects” toolbar and select a
program you wish to run.
7. Workspaces
A “workspace” in jGRASP is a logical concept. Initially projects are associated with the default
workspace. You can create your own workspace and add projects to it. The File menu has an entry
Workspace, which has commands to choose, create, or edit a workspace. A workspace description is
stored in a .gws file in the .grasp_settings/workspaces folder somewhere in the user’s system
data area.
As an example, let’s set up a project for the BalloonDraw program (Java Methods, Section 4.2), which
uses the balloondraw.jar library. Create a new project and add BalloonDraw.java to it. An
attempt to run the program generates a list of errors because several required classes from
balloondraw.jar are missing:
10 GETTING STARTED WITH JGRASP FOR JAVA
3. Navigate to the jar file you need to add to the project and click Choose.
GETTING STARTED WITH ECLIPSE FOR JAVA 11
Click OK.
If a jar file includes a class that is explicitly added to a project, the class in the project takes
precedence over the class in the jar.
For example, we can add Balloon.java to the project and edit it. Balloon.class in the project will
take precedence over Balloon.class in balloondraw.jar.
The same jar file can be runnable and can also serve as a library.
jCRASP allows you to quickly create a library or an executable jar file for a project. From the Project
menu choose Create JAR or Zip File For Project. On the window that pops up, select the type
of the jar or zip file, the classes that go into it, and its destination. See jGRASP’s Help and tutorials for
details.