java impl of calc