updated Java code