Write the java logic