refine Encoding of java and add unit test