Environment Variable is showing different value

Hello All,

I am facing quite weird problem with JAVA_HOME variable.
When am running echo $JAVA_HOME on the machine it is showing verison 1.8 but when same thing is ran from other server via script it is showing 1.7. Am pasting the output below.I had verified the profile.d and .bash_profile files and it is properly set up Java 1.8 version.

Output from other server : 
ssh Machine_Name "date;java -version;echo $JAVA_HOME"
Thu Sep 17 07:02:59 UTC 2015
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
/usr/java/jdk1.7.0_17

Output of JAVA_HOME on server itself: 
$ date;java -version;echo $JAVA_HOME
Thu Sep 17 08:50:29 UTC 2015
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)
/usr/java/jdk1.8.0_45
$ 


Try sourcing .profile and also escape the dollar sign:-

ssh -q Machine_Name ". ~/.profile>/dev/null;date;java -version;echo \$JAVA_HOME"