refactor java backend to use more dependency injection

**please review**