FP implementation in Java