Introduction to Computer Science - Lab 1 - jGRASP

(click for Eclipse Version)

Name_______________________________ Section ___________Score____________

Objectives:

The objectives of this lab are the following:

  1. To become familiar with the basics of Microsoft Windows XP
  2. To become familiar with the jGRASP (or Eclipse) Programming Environment and the Help System
  3. Learn about creating Java programs through the jGRASP (or Eclipse) IDE
  4. Edit, compile, and execute a simple Java program
  5. Investigate various error messages generated by the compiler
Background:

In the early days of programming, programs were written in machine language using paper and pencil. This task was very tedious and required many calculations and careful planning. The resulting program was a sequence of numbers that had to be transcribed into a machine readable format, perhaps on computer cards using a card punch machine. Errors were difficult to detect and had to be located manually. Small errors often required much time and effort to correct.

Modern programming environments have changed the way programming is done. The jGRASP and Eclipse programming environments provide an editor that supports text-processing operations required by modern programmers. It is integrated with tools that also support syntax checking, language help, and program testing and debugging. Today, most programming applications are managed using some type of software engineering tool to manage the development executables, libraries, test programs, and data sets. In the past, "Makefiles" were used to only compile and link only those source code files that were modified by a programmer. "Revision Control Systems" were used as a type of changes made for an application and to have several versions of an application readily available. Makefiles and revision control systems are still popular today, but there are many programming environments that use the concept of a "Project" to manage the development of programs. In the jGRASP and Eclipse environment, there is always an active project, yet simple programs can be created without worrying about the additional complexities afforded by the project concept.

The jGRASP and Eclipse help facility is always accessible by pressing F1. Help is available through a table of contents, an index, or through a search pane. Each help section includes keywords and related topics that may be easily explored with a click of the mouse. This type of help system is an example of the hypertext concept similar to that used by Netscape or Internet Explorer.

Experimental Procedure/ Analysis:

Task 1: In this exercise, you will learn how to create a simple Java application. This will include editing, compiling, and executing the program. To get started, you should read through the following tutorial: jGRASP Introductory Tutorial. Once you understand the basic features of the jGRASP environment, you will want to try it out for yourself. Follow these instructions using the tutorial as a reference.

  1. Start jGRASP on your workstation.
  2. Create a new Java file and enter the program shown below. You can copy and paste it or simply type it in. Be sure to pay close attention to upper and lower case letters and punctuation and spelling. Programming languages are very picky about such details.

    /**
       COPYRIGHT (C) 2004 Tim Margush. All Rights Reserved.
       ICS Lab 1 - Testing Integer Sizes.
       University of Akron
       @author (Your Name Here)
       @version 1.01 (date here)
    */
    public class TestInteger
    {
       public static void main(String[] args)
       { 
          int Test = 100; //Set the Test value here

          System.out.print( "The value of test is " );
          System.out.println( test );
          System.out.print( "The value of test is " );
          System.out.println( test+1 );
       }
    }

  3. Next, save the program in a file you create in your My Documents folder. Name the folder ICS_Lab1. The file name should match the name of the class in the program ().
  4. Now that the editing is complete, you should compile your program. In the compile message area of the IDE you will notice several messages being displayed. This window is used to report on the status and results of the compile step. Some messages indicate that your file is compiling; other messages report errors and warnings. You should get at three errors - if not, carefully compare what you typed to what is printed above and recompile. Record the first error message that is found in the compile message window:

  5. _______________________________________________________________________
  6. If you click on an error message, the error message will be highlighted as well as the line of source code where the error occurred. What line is referenced by the second error message? (copy it here)

  7. _______________________________________________________________________
     
  8. In this case, the actual error occurs on a line preceding the point where the first error is detected. The variable declaration misspelled the variable name. Correct the program by changing the uppercase 'T' to a lowercase 't'. Save your changes, and compile again. Can you determine what keyboard shortcut can be used to compile a program as an alternative to clicking the compile button or accessing the Compile menu? Hint: Look at the menus.

    Compile shortcut key: _____________________________

    Note: Each time you compile, the new messages are appended to the compile message window. You may wish to clear this window to avoid confusion.
  9. When the compile succeeds, a class file will be created. This class file should be located in the same folder as the source file. Click the refresh button (has an R on it) in the browse window of the jGRASP IDE. What is the name of the class file that appears?

    _________________________________________________________________________
  10. Next we should execute (run) the program to see if it does what we intended. There is a keyboard shortcut for this action as well. What is it?
  11. Run shortcut key: __________  

  12. Run the program! Output will appear in jGRASP's Run I/O window at the bottom of the IDE.

  13. What is the second line of output from the program?
     
     _______________________________________________________________________
    Note: Each time you run a program the new output is appended to the content of the I/O window. You may wish to clear this window to avoid confusion.
  14. What happens if you change the name of the class from TestInteger to TestNumber and recomple?

    ________________________________________________________________________
    What does this tell you about the class name and the file name in a Java class file?

    ________________________________________________________________________
  15. Correct the class name, then change the first occurrence of System to system. Compile and record the error message:

    ________________________________________________________________________
  16. Fix the error you introduced, then remove the semicolon (;) from the end of the line where the variable test is declared. Compile and record the error message:

    ________________________________________________________________________
  17. Fix the program before going on to the next section
Task 2: Exploring the Java documentation files.
  1. Use a web browser to locate the online Java API documentation (http://java.sun.com/j2se/1.5.0/docs/api/index.html).
  2. Click the Help link at the top of the page and then tell what API stands for:

    __________________________________________________________________
  3. Click the Index link and lookup the method: println(). (You will find several similar entries... click on the one for println(int) that is in the PrintStream class. According to the method description, what does this method do?

    _______________________________________________________________________(1 sentence)
  4. Click the link to the print(int) method and tell what method call is used by print to convert an integer to a String for printing:

    ___________________________________________________________________
  5. In the top left panel of the API documentation window, select the package named java.lang.
  6. In the left bottom panel, select the class named Integer.
  7. Documentation for this class appears in the panel to the right. Locate the description of the constant named MAX_VALUE and record its value here:

    ______________ 
  8. What is the significance of the exponent? (Hint: http://www.artima.com/underthehood/logic.html)

    _____________________________________________________________________________
  9. Use a calculator or other means to rewrite the above expression as a single integer: __________________
  10. In the program, change the literal value 100 to the largest number that can be stored in a variable of type int. Compile the program, execute it, and record the two values that are displayed:

    __________________ and ___________________
  11. Did a runtime error occur? _________________ (did you observe an error message)

    Was the correct value for test+1 displayed? _____________

    Explain:

Finishing Up

Close the browser window and jGRASP. At this time you should move your project folder (and contents) to your network storage area (Z drive) for safe keeping. You can do this in the Lab using the file explorer. Remember to always copy the entire project (program) folder. 

You should always keep each programming project in a meaningfully named folder. If you are not in a Lab, you can use WinSCP to copy your files to your Linux account. 

After copying for safe keeping, be sure to erase your folder from the local file system.

Log Off before leaving the Lab. Remember to turn in your completed lab.

Conclusions:

In this lab we have learned the basics of Windows XP and how to create a simple Java program using the jGRASP IDE. We have also explored the Java API documentation so we can quickly get help on various topics. The on-line documentation is a necessary reference and it can help us in program development and in learning the Java language.