Java book exercise