JMU
Lab: Skills - Using jGRASP for Editing Text


http://imgs.xkcd.com/comics/real_programmers.png
(Courtesy of xkcd)

Instructions:Omitted

Getting Ready:Omitted

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:
  1. Run jGRASP (by clicking or double-clicking on the jgrasp.gif icon on your desktop.
  2. "Clean up" jGRASP by clicking on File and pulling down to Close All.
  3. 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.
  1. 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.)
  2. What text appears in the title bar of the window that opened.


    Something like:
        [Grasp 1] - jGRASP CSD (Plain Text)
        
  3. Click in the window and type: "Thats what tiggers do best."
  4. What changed in the title bar?


    There is now an asterisk (i.e., '*').
  5. Click on File, pull down to Save, select an appropriate directory/folder, enter the file name junk.txt, and click on Save.
  6. What changed in the title bar?


    It now contains the file name and the asterisk is gone.
  7. 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.
  8. Select the entire sentence That's what tiggers do best., click on Edit-Copy, click below this sentence, and click Edit-Paste.
  9. What happened?


    It copied and pasted the sentence:
        That's what tiggers do best.
        
  10. Open oliver-twist.txt by clicking on File, pulling down to Open, selecting the appropriate file and directory, and clicking on Open.
  11. Click on Edit-Find/Replace, enter the text Fagin in the Find: box, and click on Find
  12. What happened?


    The cursor moved to the first instance of the word Fagin and highlighted it.
  13. What line and column is the cursor on now? (Hint: Look at the bottom of the jGRASP window.)


    Line 2650, column 21.
  14. Click on View-Line Numbers
  15. 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.
  1. Open Weight.java. (In case you couldn't guess, it's written in Java.)
  2. For readability, all of the words return should line up (i.e., should start in the same column). Do they?


    No.
  3. Click on View-Generate CSD.
  4. Do all of the words return line up now?


    Yes.
  5. Click on View-Remove CSD.
  6. Do all of the words return still line up?


    Yes.
  7. The word public is a reserved word in Java so, jGRASP presents it in a special color.
  8. What color?


    On my machine, purple.
  9. Go to any instance of the word public and delete the b.
  10. What color is it now?


    On my machine, black. Hence, it must be a typo.
  11. Fix the typo you just created (i.e., change it back to public).
  12. 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!
  13. Close Weight.java (and only Weight.java).
  14. Open WhatAnEgo.java.
  15. 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.
  16. What color?


    On my machine, orange.
  17. 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.
  18. String literals are enclosed in quotes in Java (and many other programming languages). jGRASP presents String literals in a special color.
  19. What color?


    On my machine, grean.
  20. Turn on line numbers.
  21. Delete the quotation mark near the end of line 14 (i.e., the second quotation mark on the line).
  22. 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.
  23. Click on Edit and pull down to Undo (to restore the qutation mark).
  24. Delete the quotation mark near the beginning of line 14 (i.e., the first quotation mark on the line).
  25. What happened?


    Prof. changes to black and everything after the quotation mark on that line is green, indicating that everything is messed up
  26. 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.
  27. 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.
  1. Click on jgrasp-compile.gif to compile WhatAnEgo.java (i.e., to create a file named WhatAnEgo.class containing equivalent byte codes).
  2. What text is displayed in the "Compile Messages" area?


    Something like:
     ----jGRASP exec: javac -g WhatAnEgo.java
    
    
     ----jGRASP: operation complete.
        
  3. What information is this text conveying?


    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.

  4. Click on Build and check Run Arguments several times and watch what happens (under the toolbar).
  5. 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.
  6. Make sure Run Arguments is checked.
  7. Enter your Professor's last name in the "Run Arguments" textfield.
  8. Click on jgrasp-run.gif to run this file.
  9. 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.
        
  10. 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.

  11. 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.
  12. What happened?


    The lines are highlighted in gray to indicate that they are selected.
  13. Click on Edit and pull down to Comment.
  14. What happened?


    jGRASP made the lines comments (so they turned orange on my machine).
  15. Compile and run this version of the program.
  16. What text is displayed in the "Run I/O" area?


    Something like:
    ----jGRASP exec: java WhatAnEgo Bernstein
    
    Prof. Bernstein
    
     ----jGRASP: operation complete.
        
  17. 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.
  18. 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.
  1. If it isn't activated already, activate line numbering.
  2. On line 17, change print to prnt.
  3. Compile WhatAnEgo.java.
  4. 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
        
  5. This message is telling you that WhatAnEgo.java could not be compiled because it contains a syntax error.
  6. 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.
  7. 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.
  8. The next line contains the symbol that the compiler couldn't recognize. What symbol was it?


        prnt(java.lang.String)
        
  9. 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.
  10. 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.
  11. On line 17, change prnt back to print.
  12. Compile WhatAnEgo.java. (It should compile properly.)
  13. 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.
  1. Run WhatAnEgo without any "Run Arguments".
  2. 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)
    
        
  3. What line in WhatAnEgo.java caused the String "Prof." to be printed?


    Line 14.
  4. 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
  5. 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
         
  6. The previous line in the "Run I/O" area describes the error (also called an exception). What was the error?


    java.lang.ArrayIndexOutOfBoundsException: 0
        
  7. 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.
  8. What array was used in that statement?


    args
  9. 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).
  1. 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.
  2. Click on View-Fold-Fold.
  3. What happened?


    The text "disappeared" and an icon with a "+" appeared in its place.
  4. Repeat the process for the text in Chapter II.
  5. Click next to the "+" beneath the text CHAPTER I and click on View-Fold-Unfold.
  6. What happened?


    The text of Chapter II "reappeared".
  7. 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.
  8. Make oliver-twist.txt the active window.
  9. Move the cursor to the top of the document and find the text magistrate.
  10. Click on View-Bookmarks- Toggle Bookmark
  11. What happened?


    A small icon appeared at the very left of the line.
  12. Find the third instance (after the current cursor position) of the word kitchen.
  13. Click on View-Bookmarks- Toggle Bookmark
  14. Click on View-Bookmarks- Next Bookmark
  15. What happened?


    The cursor moved to the line containing the word magistrate.
  16. Click on View-Bookmarks- Next Bookmark
  17. What happened?


    The cursor moved to the line containing the third instance of the word kitchen.
  18. Click on View-Split View- Vertical Split.
  19. What happened?


    The window split into two pieces, one above the other.
  20. 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.
  21. What happened?


    The two parts of the window now show different parts of the same file.
  22. 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.
  1. 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.
  2. Undo the paste and undo the cut.
  3. In the instructions/questions that follow, Ctrl denotes the [Ctrl] key on MS Windows keyboards and the [command] on Mac keyboards.
  4. 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.
  5. Which approach was faster.


    For me, the keyboard was much faster.
  6. Turn line numbering off by clicking on View-Line Numbers
  7. Turn line numbering on by typing Ctrl-L.
  8. Which approach was faster.


    For me, the keyboard was much faster.
  9. Split the view by clicking on View-Split View- Vertical Split.
  10. Join the view by typing Shift-F8 (Note: This might not work on some Macs.)
  11. Which approach was faster.


    For me, the keyboard was much faster.
  12. 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.
  13. Write down three other useful keyboard shortcuts.


  14. Open courses.txt.
  15. What color is the "BLK" indicator in the lower right of the jGRASP window?


    Gray
  16. Click on Edit and pull down to Block Cut/Paste.
  17. What color is the "BLK" indicator now?


    Black
  18. Click to the left of the C in CS139 and drag to the right until the space before the ( is highlighted.
  19. Drag down until all of the course numbers (and the trailing spaces) are highlighted.
  20. Either type Ctrl-x or click on Edit-Cut to cut the selected block.
  21. Click to the left of the A in Algorithm on the first line.
  22. Either type Ctrl-v or click on Edit-Paste to paste the selected block.
  23. What happened?


    The column containing the course numbers was inserted.

Copyright 2013