Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can java run a compiled scala code?

Tags:

java

scala

Can command java run a compiled scala code? If so, why do we have an exclusive command scala?

like image 639
nanda Avatar asked Sep 02 '10 10:09

nanda


People also ask

Can you run Scala with Java?

To run scala programs with the java command, you need to include the scala library as a runtime dependency of your application. I'm including the same Compile. jar from the java example as a compile time dependency, to show how everything behaves. The scala runtime is just a jar file (scala-library.

Can you convert Scala to Java?

Decompile Scala code to Java In the Project tool window, right-click a Scala library class that you want to decompile. From the context menu, select Decompile Scala to Java. IntelliJ IDEA converts code to Java and opens the converted file in the editor.

How do I run a compiled code in Scala?

To run the code, type "scala HelloWorld". You can see that "Hello, world!" is printed on the screen. Let's understand the structure of the code. It consists of a method called "main".


2 Answers

You can run byte code generated by Scala if you include all necessary runtime libs for Scala (scala-library.jar, scala-swing.jar ...) in the classpath. The scala command does this automatically, and supports Scala specific command line arguments.

like image 91
Landei Avatar answered Sep 19 '22 13:09

Landei


Yes, it can. Scala is compiled down to Java bytecode. But remember that it depends on the Scala runtime classes, so you need to still have Scala's jar files on the classpath.

If so, why do we have an exclusive command scala?

Convenience wrapper.

like image 34
Thilo Avatar answered Sep 21 '22 13:09

Thilo