find java home

C++
dirname $(dirname $(readlink -f $(which javac)))/usr/libexec/java_home
Source

Also in C++: