MODULE 1p - A Directory for Java Files


FIRST TASK

Log in to a Thor host and check the files in your home directory with
an  ls  command.  Create a directory for your Java files:

belt:c207$ mkdir java

Move your Java source code files to this directory:

belt:c207$ mv *.java java

Remove the other Java-related files from your home directory:

belt:c207$ rm Come*

Check the entries in the home directory again with an  ls  command and
then change to the  java  directory:

belt:c207$ cd java

Check the entries in the java directory with an  ls  command and then
inspect the ComeAgain.java file with a more command:

belt:java$ more ComeAgain.java
//  JAVA ASSESSED EXERCISES.  SUBMISSION 1 FROM F.H. KING.
//  Estimated time to complete: 30 mins.  Actual time: 1 hour.

public class ComeAgain
 { private static int n;

   public static void main(String[] args)
    { n = 57;
      System.out.println("Come in number " + n + " please");
    }
 }


SECOND TASK

Both uses of the  static  modifier are essential if the program is to
compile and run.  Nevertheless one can attempt to compile and run the
program when:

 1. The first  static  is removed.

 2. The second  static  is removed.

 3. Both are removed.

Interestingly, in two of the three cases, the program will compile but
not run.  In the remaining case it won't even compile.

Use emacs to modify  ComeAgain.java  so that these three possibilities
are can be tried out in turn.  For each, attempt to compile the source
and, if this is successful, try to run the compiled code.  In each case
note just what error messages are given.


THIRD TASK

Use the  cp  command to copy  ComeAgain.java  to  SevenUp.java  as:

belt:java$ cp ComeAgain.java SevenUp.java

Use emacs to modify  SevenUp.java  so that it is as follows:

public class SevenUp
 { public static void main(String[] args)
    { int i, j;
      i = 50;
      j = i + 7;
      System.out.println("Seven more than " + i + " is " + j);
    }
 }

In this program two local variables are declared in the method main.
The first, i, is set to 50 and the second, j, is set to 7 more than i.

Compile and run this program.


FOURTH TASK

Modify  SevenUp.java  so that it is as follows:

public class SevenUp
 { public static void main(String[] args)
    { int i, j;
      i = 50;
      j = sevenUp(i);
      System.out.println("Seven more than " + i + " is " + j);
    }

   private static int sevenUp(int m)
    { int n;
      n = m + 7;
      return n;
    }
 }

In this program there is a second method called  sevenUp  (notice the
lower-case s) which is invoked in the statement   j = sevenUp(i);

The method gets a copy of  i  in the argument  m  and the method also
declares a local variable  n  which is assigned a value seven more
than  m  and this value is then returned to the point where the method
was invoked and assigned to j.

Compile and run this program.


FIFTH TASK

Modify  SevenUp.java  again so that it is as follows:

public class SevenUp
 { public static void main(String[] args)
    { int i, j;
      i = 50;
      j = sevenUp(i);
      System.out.println("Seven more than " + i + " is " + j);
    }

   private static int sevenUp(int m)
    { return m+7;
    }
 }

In this program the method  sevenUp  has been considerably shortened
to make it much cleaner.

Compile and run this program.

Conclude this task by inspecting the files in the working directory and
then changing to the home directory:

belt:java$ ls

belt:java$ cd


SIXTH TASK

Work through the FILES AND DIRECTORIES handout, starting from the pwd
command.


SEVENTH TASK

Try out Electronic Mail by working through the next sheet.



                   ELECTRONIC MAIL ON THOR

The mailer or e-mail system is called pine.  Before entering the
system for the very first time, check you are in your home directory
and give the command ...

belt:c207$ cp /home/c299/.pinerc .


Enter the mailer by giving the pine command ...

belt:c207$ pine

On entry for the first time, you may be asked a question or two.
Key in N for No.


To send a message ...

From MAIN MENU, WITHOUT pressing Return, key in C (for Compose Message).

Note your neighbour's identifier.  Suppose it is c208.
Key this in after            To:
Press Return.
Press Return twice more.
Key in  Trial  after         Subject:
Press Return.
Key in a message, a couple of short lines say.
To send the message, key in  ^X  (meaning Ctrl-X).
Press Return to confirm Y for Yes.
Note that the message is `copied to sent-mail' (sent-mail is a folder).


To check on sent messages ...

From MAIN MENU, WITHOUT pressing Return, key in L (for Folder List).

Note  [Select Here to See Expanded List]  in the middle of the window.
Note how pressing the leftarrow-key once or twice and the rightarrow-key
once or twice can select (highlight) and deselect  [Select Here...]
Ensure that  [Select Here...]  IS selected then press Return to See the
Expanded List.

Note that the sent-mail folder is selected.

Press V (for View Folder); note there is one message called Trial.
Press V (for View Message); you see the full message.
Press M (for Main Menu).


To receive a message (maybe the postbox flag has gone up)...

From MAIN MENU, WITHOUT pressing Return, key in L (for Folder List).

Note  INBOX  high on the left-hand side of the window.
Note how pressing the leftarrow-key once or twice and the rightarrow-key
once or twice can select (highlight) and deselect INBOX.  Ensure that
INBOX is selected.

Press Return to view INBOX; note the received message.
Press V (for View Message); you see the full message.
Press O (for Other Commands).
Press S (for Save) to save in the  saved-messages  folder.
Press Return (for Accept).
Press I (for Index) and note D  (message is Deleted from INBOX folder).
Press M (for Main Menu).


To leave Pine ...

Press Q (for Quit) and Return to confirm Yes, then read the
information at the bottom of the window.

If you have received a message and didn't save it, you may need
to press Return again to save the message in the received folder.
The first time you do this, you will need to press Return once
more to create the folder.

You may also have to press Return to expunge a deleted message.
You will get a Unix prompt after this.