An Observer Example
Here is an ‘example that demonstrates an observable object. It creates an observer class, called Watcher, that implements the Observer interface. The class being monitored is called Being Watched, It extends Observable. Inside fleeing Watched is the method counter(), which simply counts down from a specified value. It uses sleep( )to wait a tenth of a second between counts Each time the count changes, notify Observers( ) is called with the current count passed as its argument. This causes the update( ) method inside Watch-cl’ to be called, which displays the current count. Inside main(), a Watcher and a Being Watched object, called observing and observed, respectively, are created. Then, observing is added to the list of observers for observed. This means that observing updater ) will be called each time counter ) calls notify Observers ). More than one object can be an ob’server. For example, the following program implements two observing classes and adds on object of each class to the . Being Watched observer list. The second observer waits until the count reaches zero and then rings the bell The Observable class and the Observer interface allow you to implement sophisticated program architectures based on the document/view methodology. They’are also useful in multimedia situations.
The Java Util Zip Pack
The java.utll zip package provides the ability to read and write files in the popular ZIP and GZIP file formats. Both ZIP and ZIP input and output streams are available. Other classes implement the ZLIn algorithms for compression and decompression.
The Java Util Jar Pack
The java.util.jar package provides the ability to read and write Java Archive GAR) files you will see ill Chapter 25 that JAR files are used to contain software componentsknown as Jnva Bemis and any associated files