Now, create the definitions for the StockPricer and StockWatcher services. First, define the listener service:

public class StockWatcher implements StockListener {
  public StockWatcher () {
  public void stockPriceUpdated (StockEvent ev) {
    System.out.println ("Stock " + ev.getSymbol () +
                        " is at price " + ev.getPrice ());

Not much is needed here. Like all services, this requires a public constructor with no arguments. Aside from that, it implements StockListener by printing the current stock price.

Copyright © 1997, 2013 Oracle and/or its affiliates. All rights reserved. Legal Notices