<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_java_binpath(cmd=None):
 """Retrieve path for java to use, handling custom BCBIO_JAVA_HOME Defaults to the dirname of cmd, or local anaconda directory """

    if os.environ.get("BCBIO_JAVA_HOME"):
        test_cmd = os.path.join(os.environ["BCBIO_JAVA_HOME"], "bin", "java")
        if os.path.exists(test_cmd):
            cmd = test_cmd
    if not cmd:
        cmd = Rscript_cmd()
    return os.path.dirname(cmd)