Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

scalac v javac and scala v java

Tags:

java

jvm

jar

scala

So, I understand how the scalac compiler is different from javac - looking at the bytecodes produced, they looked nothing like what javac would produce - e.g. a class without a constructor.

But is the runtime any different than starting java with scala jars in the classpath? I am very certain but can someone confirm that the scala command is just a thin wrapper around java - after all they simply lauch a JRE / JDK.

like image 793
Ustaman Sangat Avatar asked Jan 06 '12 19:01

Ustaman Sangat


2 Answers

The scala command is basically a script that sets up the classpath and then runs your code in the Java Runtime environment.

The relevant line in the scala script appears at the end:

exec "${JAVACMD:=java}" $JAVA_OPTS -cp "$TOOL_CLASSPATH" -Dscala.home="$SCALA_HOME" -Denv.emacs="$EMACS"  scala.tools.nsc.MainGenericRunner  "$@"

Basically, this starts java running MainGenericRunner. MainGenericRunner then checks whether you have told scala to run one of your Scala classes. If so, it starts running that. Otherwise, it stars up the interactive interpreter.

like image 50
Jack Edmonds Avatar answered Oct 04 '22 04:10

Jack Edmonds


Scala (on linux, anyway) is a script. The contents can be seen by typing more`which scala`

You are mostly right, it basically sets up an environment and then runs java.

like image 22
Chris Shain Avatar answered Oct 04 '22 04:10

Chris Shain