code from Agile Java book