Check out example codes for "finda java home". It will help you in understanding the concepts better.

Code Example 1

dirname $(dirname $(readlink -f $(which javac)))

Learn ReactJs, React Native from akashmittal.com