Installing and configuring Java for Mathematica on Mac

Mathematica 9.0.2.0, Mac OS X 10.10.3

Start Mathematica from Dock

Start Mathematica from Dock, install Java with CommandLine->”java”

<<JLink`

InstallJava[CommandLine->"java"]

Import["!echo $JAVA_HOME","Text"]

Environment["JAVA_HOME"]

Import["!java -version","Text"]

Needs["JLink`"]
LoadJavaClass["java.lang.System"]
java`lang`System`getProperty["java.version"]

Start Mathematica from Dock, install Java without CommandLine->”java”

<<JLink`

InstallJava[]

Import["!echo $JAVA_HOME","Text"]

Environment["JAVA_HOME"]

Import["!java -version","Text"]

Needs["JLink`"]
LoadJavaClass["java.lang.System"]
java`lang`System`getProperty["java.version"]

Start Mathematica from command line

Install Java with CommandLine->”java”, use ‘export JAVA_HOME=`/usr/libexec/java_home -v 1.6`’ in $HOME/.baschrc

JLink`Package`$DebugCommandLine=True;
<<JLink`

UninstallJava[]

InstallJava[CommandLine->"java"]

Import["!echo $JAVA_HOME","Text"]

Environment["JAVA_HOME"]

Needs["JLink`"]
LoadJavaClass["java.lang.System"]
java`lang`System`getProperty["java.version"]
strObj=JavaNew["java.lang.String","foobar"]

Install Java with CommandLine->Automatic, use ‘export JAVA_HOME=`/usr/libexec/java_home -v 1.6`’ in $HOME/.baschrc

<<JLink`

UninstallJava[]

InstallJava[]

Import["!echo $JAVA_HOME","Text"]

Environment["JAVA_HOME"]

Import["!java -version","Text"]

Needs["JLink`"]
LoadJavaClass["java.lang.System"]
java`lang`System`getProperty["java.version"]
strObj=JavaNew["java.lang.String","foobar"]

Install Java with CommandLine->”java”, use ‘export JAVA_HOME=`/usr/libexec/java_home -v 1.8`’ in $HOME/.baschrc

Environment["JAVA_HOME"]

Environment["WRI_JAVA_HOME"]

SetEnvironment["WRI_JAVA_HOME"-> Environment["JAVA_HOME"]]

Environment["WRI_JAVA_HOME"]

JLink`Package`$DebugCommandLine=True;

SystemInformation["Small"]

<<JLink`

UninstallJava[]

InstallJava[CommandLine->"java"]

Import["!echo $JAVA_HOME","Text"]

Environment["JAVA_HOME"]

Needs["JLink`"]
LoadJavaClass["java.lang.System"]
java`lang`System`getProperty["java.version"]
strObj=JavaNew["java.lang.String","foobar"]

Install Java without CommandLine->Automatic, use ‘export JAVA_HOME=`/usr/libexec/java_home -v 1.8`’ in $HOME/.baschrc

Environment["JAVA_HOME"]

Environment["WRI_JAVA_HOME"]

SetEnvironment["WRI_JAVA_HOME"-> Environment["JAVA_HOME"]]
Environment["WRI_JAVA_HOME"]

JLink`Package`$DebugCommandLine=True;

<<JLink`

UninstallJava[]

InstallJava[]

Import["!echo $JAVA_HOME","Text"]

Environment["JAVA_HOME"]

Needs["JLink`"]
LoadJavaClass["java.lang.System"]
java`lang`System`getProperty["java.version"]
strObj=JavaNew["java.lang.String","foobar"]