We have a change of plans. Originally we planned to do Collections and Generics, but instead we will do IO now.
In this lecture will shall look at I/O (Input/Output) and its different usages. I/O is a universal issue for any programming language to handle - we shall of course look at Javas way of implementing it.
I/O is basicly about getting access to external resources - it is used whenever a program wants to get information from or send information to sources outside itself.
The task of implementing an I/O library is a challenging one, since such a library has to provide functionality for communicating with a number of different media (files, the console, network connections), in a wide variety of ways (sequential, random-access, buffered, binary, character, by lines, by words, etc.).
The way Java has decided to solve this problem is to have a number of classes with basic functionality, and a number of classes with additional functionality that the programmer can wrap the basic classes with. This approach of course gives a high level of flexibility, but also explains why the I/O library seems, at a first glance, at best complex, if even not completely confusing and incomprehensable.
The lecture and excercises will hopefully guide you through the jungle of Java I/O, and equip you with an understanding which will make it possible for you to find your way through on your own.
Write a class FileInfo.java, which takes the path of a directory as parameter to the constructor (so that you e.g. can make a FileInfo object with this call: FileInfo fi = new FileInfo("c:/oop/lecture5/excercises");).
In this excercise you should make a class called WriterFork.java, which extends java.io.Writer. The idea of this class is that it is connected to two other writers, which it writes to whenever somebody calls its write() method. The WriterFork should get references to these two other writers in its constructor, like this: public WriterFork(Writer a, Writer b). If we call write("Hello") on the WriterFork object, it should call write("Hello") on both its Writers. Write a test program with a main method that tests if the WriterFork is working as intended, e.g. make it write to both a file and the console.
This excercise is about the construction of a logging facility, which should keep a log file of everything that one might want to monitor in a program execution (similar to the way System.out.println is often used).
In this excercise you will make some experiments with object serialization using ObjectOutputStreams and ObjectInputStreams.
In this excercise you should write a client and a server communicating through sockets. You can use the example in JP page 105 as inspiration. The server should answer requests about taxes: when the client provides the server with information about how much he or she has earned, the server replies with a calculation of how much tax the client should pay. You are free to implement it with the tax rate of your dreams...