My preliminary code in java.