How does one detect if java is installed without triggering a visual prompt? On most systems, one would just run java -version and a non-zero return code would indicate that Java is not installed.

One could do this on OS X, but a nuisance-prompt comes up to ask the user if they want to install Java.

This is irritating in automated scripts.

How can one detect whether Java is installed on a Mac, without getting the popup?
rtrouton has some great examples on his derflounder website.  The examples are used as extension attributes in a mdm suite, just remove the results tags from them.  Below is a script that looks for the java install folder, if it exists echo out the version if not echo not installed.  This in return never triggers the java command keeping the pop up away.

if [[ -e /Library/Java/Home ]]; then
    echo "$(java -version 2&gt;&amp;1 | awk '/version/{print $3}' | sed 's/"//g')"
        else
    echo "Java not installed"
fi