modify java code

to be compatible for all java versions