[java] refactoring: separate the functionalities