Bash command to check if Oracle or OpenJDK java version is installed on Linux

I need a bash line to check if java version currently installed is Oracle's or OpenJDK.

A one-liner by parsing the output of the java -version command:

java -version

java Oracle output:

java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)

java OpenJDK Output:

java version "1.7.0_91"
OpenJDK Runtime Environment (amzn-2.6.2.2.63.amzn1-x86_64 u91-b00)
OpenJDK 64-Bit Server VM (build 24.91-b01, mixed mode)

Solution 1:

if [[ $(java -version 2>&1) == *"OpenJDK"* ]]; then echo ok; else echo 'not ok'; fi

Solution 2:

java -version 2>&1 | grep "OpenJDK Runtime" | wc -l

returns 0 if using Oracle JDK, 1 if using OpenJDK

Bash condition:

if [[ $(java -version 2>&1 | grep "OpenJDK Runtime") ]]