Exercises

  1. (Random Access Files) Create a data file that contains ten ints and a long. The long value holds the total of the ints. Write a program that repeatedly checks the total is correct, chooses one of the ten ints at random, changes it to a random value, and updates the total.

  2. (Serialization) Write a program that creates a java.util.Vector object and adds various arrays to it. Serialize the Vector to a file. Read the Vector back in, and write the code to check that it contains the same contents that it had when written out. Modify the serialized file to give one of the arrays different content. (Hint: strings are easy to update in a file.) Check that your program detects the change.

  3. (Channels, Buffers) Write a program that has two threads. One thread should engage in I/O using a channel. It should contain a handler for ClosedByInterruptException and AsynchronousCloseException. The other thread should call the interrupt method of the first thread. The first thread should catch the exception, re-open another channel and carry on with I/O. Put the whole thing in a loop and run it overnight. Is it reliable enough that it is still running in the morning? Is your operating system reliable enough to cope with this?

  4. (Channels, Buffers) Write a program to measure the difference in performance between I/O through a direct (mapped) buffer and a non-direct buffer. Your program should output a 512 KByte array of ints 1,000 times in a loop to the same random access file. Is the performance of input any different? Account for any differences.

  5. (Channels, Buffers) Take the example program that shows memory-mapped I/O for an input file and modify it so that the output is done by mapped I/O too.

  6. (Locking) Take the program written for the random access file exercise (question 1 above). Run two copies of the program and demonstrate that the total quickly goes awry.

  7. (Locking) Update the program in the previous exercise to protect the file by locking it. Run several copies of the program overnight to show that it works correctly.

  8. (Locking) Update the program in the previous exercise so that it locks only the regions of the file that it is going to update: the random int and the total field. Measure the performance of this code and compare it with the code from the previous exercise. Is it faster or slower? Account for any performance differences.

  9. (Encodings) Write a program that prints a neat table of EBCDIC and ASCII characters and their associated bit patterns.

  10. (Encodings) Write a codeset program to write out data in all the standard encodings and confirm how the bytes are swapped with the different character sets.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.178.151