1. Starting jGRASP:
There are many different text editors. and most programmers have their
personal favorite. For this lab you will be using the text editor
in the integrated development environment (IDE) call jGRASP.
To get started:
Run jGRASP (by clicking or double-clicking on the
icon on your desktop.
"Clean up" jGRASP by clicking on File and pulling
down to Close All.
Open cs139.txt by clicking on File,
pulling down to Open, selecting the appropriate
file and directory, and clicking on Open.
2. Basic Text Editing:
This part of the lab will help you gain skills with basic text editing.
Create a new temporary file by clicking on File,
pulling down to New, and selecting
Plain Text. (Note: If "Plain Text" is not an option
you may need to first pull down to Other.)
What text appears in the title bar of the window that opened.
Something like:
[Grasp 1] - jGRASP CSD (Plain Text)
Click in the window and type:
"Thats what tiggers do best."
What changed in the title bar?
There is now an asterisk (i.e., '*').
Click on File, pull down to Save,
select an appropriate directory/folder, enter the file name
junk.txt, and click on Save.
What changed in the title bar?
It now contains the file name and the asterisk is gone.
What do you think the asterisk in the title bar indicates
(when it is there)?
The file has been changed since it was last saved.
Select the entire sentence That's what tiggers do best.,
click on Edit-Copy, click
below this sentence, and click
Edit-Paste.
What happened?
It copied and pasted the sentence:
That's what tiggers do best.
Open oliver-twist.txt by clicking on File,
pulling down to Open, selecting the appropriate
file and directory, and clicking on Open.
Click on Edit-Find/Replace, enter the
text Fagin in the Find: box, and click on
Find
What happened?
The cursor moved to the first instance of the word Fagin and
highlighted it.
What line and column is the cursor on now? (Hint: Look at the bottom of the
jGRASP window.)
Line 2650, column 21.
Click on View-Line Numbers
What happened?
Line numbers appeared on the left side. They are not part of the
text.
3. Text Editing Functionality for Programmers:
This part of the lab will help you gain skills with text editing
functionality that is especially useful for programmers.
Open Weight.java. (In case you couldn't guess, it's
written in Java.)
For readability, all of the words return should line up
(i.e., should start in the same column). Do they?
No.
Click on View-Generate CSD.
Do all of the words return line up now?
Yes.
Click on View-Remove CSD.
Do all of the words return still line up?
Yes.
The word public is a reserved word in Java so, jGRASP
presents it in a special color.
What color?
On my machine, purple.
Go to any instance of the word public
and delete the b.
What color is it now?
On my machine, black. Hence, it must be a typo.
Fix the typo you just created (i.e., change it back
to public).
If this were an episode of Beavis and Butt-Head,
what letter in public would I have had you delete?
That question is beneath me!
Close Weight.java (and only Weight.java).
Open WhatAnEgo.java.
All of the text between a /* and a */
is a comment in Java (and many other programming languages).
jGRASP presents comments in a special color.
What color?
On my machine, orange.
How else can you include a comment in a Java program?
Everything on a line after a double-slashes is a comment.
You can tell because it is orange in jGRASP.
String literals are enclosed in quotes in Java
(and many other programming languages).
jGRASP presents String literals in a special color.
What color?
On my machine, grean.
Turn on line numbers.
Delete the quotation mark near the end of line 14 (i.e., the second
quotation mark on the line).
What happened?
Everything after the quotation mark on that line is green, indicating that
jGRASP thinks all of those characters are part of the
String literal.
Click on Edit and pull down to Undo
(to restore the qutation mark).
Delete the quotation mark near the beginning of line 14 (i.e., the first
quotation mark on the line).
What happened?
Prof. changes to black and everything after the
quotation mark on that line is green, indicating that
everything is messed up
What happens if you hover the mouse cursor over an
open or close curly bracket?
It is highlighted and its corresponding
closing or opening curly bracket is highlighted.
Undo your last change. (At this point the file should be in
its original state. If you're not sure that it is, close the file
without saving it and re-open it.)
4. Integrated Development Environments (IDEs):
This part of the lab will help you gain skills with
an IDE.
Click on to compile
WhatAnEgo.java (i.e., to create
a file named WhatAnEgo.class containing
equivalent byte codes).
What text is displayed in the "Compile Messages" area?
It's indicating that jGRASP compiled the file named WhatAnEgo.java
using the javac command.
Note: You could have done the same thing in a command shell.
Click on Build and check Run Arguments
several times and watch what happens (under the toolbar).
What happens?
A textfield for entering the "Run Arguments" (also called
command line arguments) appears when the box is checked and
disappears when it isn't.
Make sure Run Arguments is checked.
Enter your Professor's last name in the "Run Arguments" textfield.
Click on to run
this file.
What text is displayed in the "Run I/O" area?
Something like:
----jGRASP exec: java WhatAnEgo Bernstein
Prof. Bernstein is the best!
----jGRASP: operation complete.
What information is this text conveying?
First, it's indicating that jGRASP executed the program WhatAnEgo.class
using the java command passing it a single
command-line argument containing the String "Bernstein".
It then shows the output that is generated by the program.
Note: You could have done the same thing in a command shell.
You've decided that the program isn't doing what it should and you're
thinking of deleting lines 16 and 17. However, you're not sure and
you don't want to re-type them if you don't have to. So, click on the
left side of that line (not on the 16) and, keeping the mouse-button
pressed, drag down to the next line.
What happened?
The lines are highlighted in gray to indicate that they are selected.
Click on Edit and pull down to Comment.
What happened?
jGRASP made the lines comments (so they turned orange on my machine).
Compile and run this version of the program.
What text is displayed in the "Run I/O" area?
Something like:
----jGRASP exec: java WhatAnEgo Bernstein
Prof. Bernstein
----jGRASP: operation complete.
You were wrong, the program was correct before. So,
select the lines that you just "commented out" (if they are not
still selected), click on Edit and pull down
to Uncomment.
What happened?
jGRASP removed the comment indicators.
5. Syntax Errors:
This part of the lab will help you gain the skills you need
to understand syntax errors that are generated by the compiler.
If it isn't activated already, activate line numbering.
On line 17, change print to prnt.
Compile WhatAnEgo.java.
What is displayed in the "Compile Messages" area?
Something like:
WhatAnEgo.java:17: cannot find symbol
symbol : method prnt(java.lang.String)
location: class java.io.PrintStream
System.out.prnt("\n"); // '\n' is the newline char
^
1 error
This message is telling you that WhatAnEgo.java could not
be compiled because it contains a syntax error.
There is a number after the text WhatAnEgo.java and
between two colons. What do you think this number indicates?
The line number containing the syntax error.
There is an error message after the colons that says something like
cannot find symbol. What do you think this means?
The compiler could not recognize a symbol.
The next line contains the symbol that the compiler couldn't
recognize. What symbol was it?
prnt(java.lang.String)
This method meand that you used a function named prnt that is
passed a String and that the compiler does not think there
is such a function.
The next line contains the statement containing the problem. Under that is
a line with a ^ (called a caret). What is the caret pointing at and why?
It is pointing at the last character that does not contain
a syntax error. In this case, System.out. is
fine and that the problem is after that.
On line 17, change prnt back to print.
Compile WhatAnEgo.java. (It should compile properly.)
Make some other changes that cause syntax errors, re-compile
WhatAnEgo.java, and make sure you can interpret the
error messages. When you are done, change everything back so that
the program compiles correctly.
6. Run-Time Errors:
This part of the lab will help you understand the difference
between compile-time errors and run-time errors.
Run WhatAnEgo without any "Run Arguments".
What is displayed in the "Run I/O" area?
Something like:
Prof. Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0
at WhatAnEgo.main(WhatAnEgo.java:15)
What line in WhatAnEgo.java caused the
String "Prof." to be printed?
Line 14.
On the next line is a run-time error message. What does it tell you about
what line caused the run-time error?
It says that the run-time error was caused by line 15 of
WhatAnEgo.java
What statement is on that line? In other words, what statement
in WhatAnEgo.java caused the run-time error?
System.out.print(args[0]); // args[0] should be a name
The previous line in the "Run I/O" area describes the error (also
called an exception). What was the error?
java.lang.ArrayIndexOutOfBoundsException: 0
This error means that the offending statement used element 0 of an array
but that there was no such element when the program was running.
What array was used in that statement?
args
Why wasn't there an element 0?
Because we didn't provide any "Run Arguments".
7. More Advanced Text Editing:
This part of the lab will help you gain some more advanced text editing
skills (that will prove beneficial throughout the semester).
Scroll to the top of the window containing oliver-twist.txt,
click to the line below CHAPTER I, and select all of the text
from the current cursor position to the line before
CHAPTER II.
Click on View-Fold-Fold.
What happened?
The text "disappeared" and an icon with a "+" appeared in its place.
Repeat the process for the text in Chapter II.
Click next to the "+" beneath the text CHAPTER I and click on
View-Fold-Unfold.
What happened?
The text of Chapter II "reappeared".
You can do the same thing with Java source code.
Make WhatAnEgo.java the active window and
click on View-Generate CSD.
Now, move the cursor to the line containing main()
and click on
View-Fold-Fold.
This can be very useful when you want to work in a top down fashion,
ignoring some of the details.
Make oliver-twist.txt the active window.
Move the cursor to the top of the document and find the text
magistrate.
Click on View-Bookmarks-
Toggle Bookmark
What happened?
A small icon appeared at the very left of the line.
Find the third instance (after the current cursor position)
of the word kitchen.
Click on View-Bookmarks-
Toggle Bookmark
Click on View-Bookmarks-
Next Bookmark
What happened?
The cursor moved to the line containing the word magistrate.
Click on View-Bookmarks-
Next Bookmark
What happened?
The cursor moved to the line containing the third instance of
the word kitchen.
Click on View-Split View-
Vertical Split.
What happened?
The window split into two pieces, one above the other.
Click in the top half of the window and find the next instance of the
word beadlehood. Click in the bottom half of the window and
find the next instance of the word shopkeepers.
What happened?
The two parts of the window now show different parts of the
same file.
Click on View-Split View-
Joined.
Note: This part of the lab allows you to "go further" on this material. It is neither required nor for extra credit. It will, however, help you gain a deeper understanding of the material. 8. The Keyboard and the Mouse:
This part of the lab will help you determine whethe you are more
productive using the keyboard or the mouse.
Using the mouse, scroll to the top of the file, select the first paragraph,
cut the selected text, go to the bottom of the file, and paste the
selected text.
Undo the paste and undo the cut.
In the instructions/questions that follow, Ctrl denotes the
[Ctrl] key on MS Windows keyboards and the [command] on Mac keyboards.
Using the keyboard, type Ctrl-T, 15 Enter.
Then hold the Shift and press the down arrow until the
first paragraph is selected. Then type Ctrl-x,
Ctrl-End, Ctrl-v.
Which approach was faster.
For me, the keyboard was much faster.
Turn line numbering off by clicking on
View-Line Numbers
Turn line numbering on by typing Ctrl-L.
Which approach was faster.
For me, the keyboard was much faster.
Split the view by clicking on
View-Split View-
Vertical Split.
Join the view by typing Shift-F8
(Note: This might not work on some Macs.)
Which approach was faster.
For me, the keyboard was much faster.
Other than the time required to execute the command itself,
write down another advantage of using keyboard shortcuts rather than
the mouse.
It is much easier to start typing again since your hands are still in
the right place.
Write down three other useful keyboard shortcuts.
Open courses.txt.
What color is the "BLK" indicator in the lower right of the
jGRASP window?
Gray
Click on Edit and pull down to
Block Cut/Paste.
What color is the "BLK" indicator now?
Black
Click to the left of the C in CS139
and drag to the right until
the space before the ( is highlighted.
Drag down until all of the course numbers (and the trailing spaces) are
highlighted.
Either type Ctrl-x or click on
Edit-Cut to cut the selected block.
Click to the left of the A in Algorithm
on the first line.
Either type Ctrl-v or click on
Edit-Paste to paste the selected block.
What happened?
The column containing the course numbers was inserted.