#4 done in java