One way could be to read the variable 'JAVA_HOME'.
But developers often install multiple instances to
- ensure compatibility with old customer JREs
- ensure compatibility to old tools, not supporting newest JDKs (UML-tools, ...)
- have a mature JDK available
- have a bleeding-edge unstable pre-alpha-release for
testing and lerning.
You could get the filesystem-roots (aka: drives), and recursivly walk them down to find a directory 'jre' to find all installed JDKs.
For users it would be helpfull to easily switch between different versions, and to specify different JDKs for different project, perhaps having a default jdk specified to start with.