Improvements for Java support

Part of #933.