How to find which version of Java in Java installed folder?

I think you can track all this by checking to where your java binaries linked to.

       #which javac
          /usr/bin/javac   
       #ls -ln /usr/bin/java
           lrwxrwxrwx. 1 0 0 22 Nov 27 04:54 /usr/bin/java -> /etc/alternatives/java
       #ls -ln /usr/bin/javac
            lrwxrwxrwx. 1 0 0 23 Nov 27 04:54 /usr/bin/javac -> /etc/alternatives/javac
       # ls -ln /usr/bin/javadoc
            lrwxrwxrwx. 1 0 0 25 Nov 27 04:54 /usr/bin/javadoc -> /etc/alternatives/javadoc

and finally:

#ls -ld /etc/alternatives/java
lrwxrwxrwx. 1 root root 46 Nov 27 04:54 /etc/alternatives/java -> /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java

therefore , my java installation is:

   /usr/lib/jvm/jre-1.7.0-openjdk.x86_64

I suppose you can track any binary like this.


Finding out which binary is executed when you type only the name is done using which, and using readlink you can condense the process to a single line.

readlink -e $(which java)

readlink -e prints the value of a symbolic link or canonical file name, and the -e ensures it follows every component recursively.

tony@trinity:~$ readlink -e $(which java)
/usr/lib/jvm/java-6-openjdk-i386/jre/bin/java

note: I don't have javac installed on the machine I tested this on, so just used java, but the above will work work for any binary.

You also appear to be asking to find out which version of java is in a specific folder? For that you just do this,

/full/path/java -version

which prevents Linux from search the path and finding the java binary directly. In your case,

/usr/lib/jvm/java-7-oracle/javac -version