P417: Added explanation and reorganized and tweaked Java code.