Code from O'Reilly book "Head First Java"