Albany Programming Course Supplement

Java and Unix Command Line Introductory Lab Exercise

The objective of this lab is to use basic Unix/Linux commands to manage a simple Java project that includes data files for input and output as well as Java source files. For a passing grade of 6, the project must be built in a single directory, the source and input files created with an editor, the javac and java commands must be demonstrated, and input and output redirection must be demonstrated with a program that reads and writes the standard input and output streams (in Java, System.in and System.out). For full credit of 10, timing and a shell script must be submitted and explained. The lab instructor and your classmates will give further directions and answer questions. Please DO look over each other's work but DON'T SKIP doing all the steps for yourself.

We assume you have "logged in" and have (1) a shell window and (2) a Web browser window open to the Blackboard or your college's course management system assignment submission page.

For each of these items, write a brief note into the assignment submission page or in a document to report HOW you demonstrated or used it.

  1. mkdir to make a new directory.
  2. pwd to print the name of the current working directory.
  3. cd to (a) go to another directory and verify the change with pwd and (b) go to your home directory with (b1) cd (nothing) and (b2) cd ~ (the tilde charater which means "your home directory"). Verify the two (b)s.
  4. ls to view a directory contents and ls -l to see which entries are files versus subdirectories and the sizes, dates, and protections of the files and subdirectories. Files are marked with a (hyphen) - first, and subdirectories are marked with a (letter) d first.
  5. Make a new directory for this lab.
  6. Use the text editor pico (or another, like emacs or vi, BUT NOT DrJava) to write the Hello World complete Java application.
  7. javac to compile your complete application (ASK HOW).
  8. Observe BOTH the .java file and the .class file.
  9. Open and look at the .class file with the text editor (DON'T MODIFY IT). Take a look and close it.
  10. java to run your complete application. Let's assume your application class (with the main method) is named labDemoAppl
  11. Modify your application to BOTH read from the keyboard and write to the screen. Get it to work and demonstrate it. (It should therefore use a Scanner for the input.)
  12. Prepare an INPUT FILE with the text editor. What did you name it? Let's assume you named it BILL
  13. java labDemoAppl < BILL

    What happened?

  14. java labDemoAppl > GNUFILE

    What happened? Open GNUFILE with the text editor to see.

  15. java labDemoAppl < BILL > GNUFILE2

    What happened? Open GNUFILE2 with the text editor to see.

  16. Download the following FRAMEWORK FILES. 3 Files:
    1. SortingApplication.java
    2. SortingEngine.java
    3. Sample text to sort.
  17. Compile and demonstrate the SortingApplication with keyboard input and output.
  18. Repeat but demonstrate how it sorts a "huge" file of input lines. (USE I/O redirection learned from step 15.) NOTE: When this book is sorted, all the blank lines are put at the beginning! You will need to scroll a lot to see visible text.
  19. time java SortingApplication < 27827-8.txt > timedOUTPUT.txt

    Try this and report how much time the computer that runs the commands took to run the sorting application on the big file.


  20. Put a few sample command into a shell script.
    • The shell script is a text file that begins with the line #!/bin/sh Make it with a text editor.
    • The rest of the lines can be blank, or comments if they start with # or commands to run IN THE FUTURE otherwise.
    • Suppose the file is named myscriptOne.sh
    • The chmod command in the form chmod 700 myscriptOne.sh must be given to make the script file become "executable"
    • Verify you made your script executable with the ls -l command: Observe the -rwx------
    • RUN the script by giving the command: ./myscriptOne.sh
    • Verify that it made the computer do the commands in the script.
  21. Make a script that both compiles all the .java files and then does the timed, big file sorting run when. Submit that script to Blackboard.
  22. Most Unix/Linux systems come with sorting command named sort Write a script that automates these steps:
    1. First, time our (or your own) Java sorting application on a big file. Make sure to redirect the output so it doesn't overwhelm your screen and consume time sending the data over the network.
    2. Second, time the sort command on the same big file the same way.
    3. Third, REPEAT STEP 1. (YES, really make the computer do it again.)
    4. Fourth, REPEAT STEP 2. (YES, really make the computer do it again.)

    RUN THE SCRIPT. You will get 4 time reports. Compare them. Anything weird? RUN THE SCRIPT A SECOND TIME. Report the 8 times on Blackboard and whatever you make of them.

  23. (OPTIONAL but smart) Learn more about shell scripts from the Web, and practice on itsunix or your own Linux system. Then, you will have some Unix/Linux experience to tell JOB INTERVIEWERS ABOUT when they ask!!

There has been error in communication with booki server. Not sure right now where is the problem.

You should refresh this page.