Computer Science Java Style
Introduction
Fundamental Notions and First Constructs

Laboratory Challenge: Mechanics of Java Programming

Objectives

  1. To make sure you know how to "log on".
  2. To establish your computer environment so that you will be in a positon to develop programs in the prescribed manner.
  3. To engage you in the development (writing and running) of a simple Java application program - in the prescribed manner.
  4. To introduce you to the notion of a precondition.
  5. To raise your consciousness relative to the what (declarative), the how (procedural), and the why (explanatory) forms of expression, in a natural setting.
  6. To expose you to the use of metasymbols for descriptive purposes.

Instructions

First, read the tasks in the "once over" manner. That is, read the double quoted lines. Then, perform each of tasks 1 through 18, in order, successfully completing task i prior to undertaking task i+1, for i = 1 through 17.

Tasks

  1. " Log on to the computer "
    [ The computer is turned on; the system is responsive. ]
    < Perform your login sequence. >
    ( Consult with your local system administration. )

  2. " Set up your account for Java things to come. "
    [ You are logged onto the system. ]
    [ Someone has written a program called setup which will see to it that your environment is consistent with certain conditions. ]
    < Run the shell program csjssetup >
    ( Simply type the name of the program at the unix prompt. )
    { In order to work in the prescribed manner, it is necessesary that a couple of files exist in your account and contain certain information. These files serve to partially establish your computing environment. The program setup is intended to make this desired state a reality. }

  3. " Refresh your environment."
    [ The files .cshrc and .emacs exist in your account and contain appropriate information. ]
    ( Log out and then log back in again. )
    { The program csjssetup edited a file called .cshrc in an appropriate manner. It did not change your environment consistent with the text within that file. You must can do this by logging out and then logging back in again. }

  4. " Load the Java environment file. "
    [ Your environment is setup for this course. ]
    < Enter the emacs text editor. >
    ( Type its name, emacs )
    < Split the buffer in two and start a shell in one of the two buffers. >
    ( Issue the emacs command M-x load-file and then type the file name bluejava.el at the prompt. )
    { The two buffer setup will facilitate your Java development. In the shell buffer you can conveniently compile and run the program. In the other buffer you can edit (create, modify) your program. }

  5. " Prepare to write a program. "
    [ You are in the mood for "make believe". ]
    < Pretend you want to write a program which prints the message "The coffee is good!" to the standard output file. >

  6. " Establish a buffer into which you will place the program. "
    [ You are "in" emacs, with two buffers visible, the other of which contains a shell. ]
    < Issue the "create file" command to create a file called CoffeeApp.java . >
    ( Type C-x C-f CoffeeApp.java )
    { You want to establish a file on disk corresponding to the current buffer into which you can type the Java program. }

  7. " Establish the basic Java application template. "
    [ The current buffer is empty and is named CoffeeApp.java ]
    < Run the emacs command to generate a simple java application template in the current buffer. >
    ( Issue the emacs command M-x java-app-template )
    { By working from the template you will be less likely to introduce lexical errors into your program. If you are working from scratch, typing tends to introduce lexical errors. If you were working from a copy of a "similar" program, incorrect editing, e.g., cutting or pasting, sometimes introduces lexical errors. }

  8. " Find and fill in the first <?CLASS> slot. "
    [ A simple Java application template appears in the buffer called CoffeeApp.java ]
    < Replace the <?CLASS> slot with the name of the class being defined. >
    ( Issue the emacs command C-j)
    { This will move "point" to the <?CLASS> slot. }
    ( Issue the emacs command M-j)
    { This will delete the <?CLASS> slot. }
    ( Type the name of the class being defined, CoffeeApp)
    { Including the file name is very helpful when reviewing documents that have been printed. }

  9. " Find and fill in the <?NAME> slot. "
    [ The first slot <?CLASS> is appropriately filled.]
    < Replace the <?NAME> slot with your name. >
    ( Issue the emacs command C-j )
    { This will move "point" to the <?NAME> slot. }
    ( Issue the emacs command M-j)
    { This will delete the <?NAME> slot. }
    < Type in your name. >

  10. " Find and fill in the <?LINE> slot. "
    [ The second slot <?NAME> is appropriately filled.]
    < Replace the third slot, <?LINE>, with a one line description of the program you are interested in writing. >
    ( Issue the emacs command C-j )
    { This will move "point" to the <?LINE> slot. }
    ( Issue the emacs command M-j)
    { This will delete the <?LINE> slot. }
    ( Type in the one line description. )

  11. " Find and fill in the <?DESCRIPTION> slot. "
    [ The slot <?LINE> is appropriately filled. ]
    < Replace the <?DESCRIPTION> slot with a simple description of this program. >
    ( Issue the emacs command C-j )
    { This will move "point" to the <?DESCRIPTION> slot. }
    ( Issue the emacs command M-j)
    { This will delete the <?DESCRIPTION> slot. }
    ( Type in the "multiple line" description. )

  12. " Find and fill in the <?NEEDS> slot. "
    [ The slot <?DESCRIPTION> is appropriately filled. ]
    < Delete the <?NEEDS> slot >
    { Nothing is needed from elsewhere for this simple program other than IO of the blue.io package. }
    ( Issue the emacs command C-j )
    { This will move "point" to the <?NEEDS> slot. }
    ( Issue the emacs command M-j)
    { This will delete the <?NEEDS> slot. }

  13. " Find and fill in the second <?CLASS> slot. "
    [ The slot <?NEEDS> has been deleted. ]
    < Replace the second occurrence of <?CLASS> with the name of the class being defined. >
    ( Issue the emacs command C-j)
    { This will move "point" to this <?CLASS> slot. }
    ( Issue the emacs command M-j)
    { This will delete this <?CLASS> slot. }
    ( Type the name of the class being defined, CoffeeApp )

  14. " Find and fill in the <?PROGRAM> slot. "
    [ The second occurrence of <?CLASS> has been appropriately filled. ]
    < Replace the <?PROGRAM> slot with the "sequence" of Java instructions to solve the problem. >
    ( Issue the emacs command C-j)
    { This will move "point" to this <?PROGRAM> slot. }
    ( Issue the emacs command M-j)
    { This will delete this <?PROGRAM> slot. }
    ( CAREFULLY type IO.println("The coffee is good!") )

  15. " Save the buffer to disk. "
    [ The <?PROGRAM> slot is appropriately filled. ]
    < Save the current buffer to the corresponding file. >
    ( Type M-x save-buffer to write the buffer to the file. )
    { You must save the file so that the compiler can read it in the next step. }

  16. " Compile the program. "
    [ The file CoffeeApp.java is saved to disk. ]
    < Switch to the buffer containing the shell. >
    ( Type the emacs command C-x o to get to the "other" buffer, the shell buffer in this case.)
    < Compile the program. >
    ( Type the command javac CoffeeApp.java )
    < If errors are reported, edit the Java program in the other buffer, save it, return to this buffer, and again compile the program. Repeat this process until no errors are reported. >
    { You must achieve successful compilation of your program before it can be run. }

  17. " Run the program. "
    [ The source program has been successfully compiled. That is, the file CoffeeApp.class has been created. ]
    < Run the program. >
    ( Type java CoffeeApp to run the program. )
    < If the results are not correct, edit the program, save it, compile it, and again run it - until it behaves properly. >

  18. " Transfer the demo. "
    [ The program has just run correctly in the shell window. ]
    < Transfer the demo to the last slot of the source file. >
    ( First, place "point" at the beginning of the line in shell buffer which commences the successful demo consisting of the run of the program. (Use arrow keys.) )
    ( Issue the emacs command to transfer the demo to the <?DEMO> slot in the other window. )
    ( Type M-x transfer-demo )
    < Save the source file. >


Craig Graci
Last modified: Tue Jan 21 11:25:51 EST