add java, improved comparison logic