I am a newbie to Scala, it\'s the first time I\'m running Scala, when I installed Scala, I created a file named Hello.scala
, the content is:
pr
Your file Hello.scala
is a script. You should be able to run it from the command prompt with scala Hello.scala
.
$ scala Hello.scala
HelloWorld!
The REPL, on the other hand, is not for running scripts. It is used for running scala code directly:
scala> println("HelloWorld!")
"HelloWorld!"
To execute external script (load all definitions from it) in REPL use :load <filepath>
command instead of scala <filepath>
.
» echo 'println("HelloWorld")' > Hello.scala
» scala
Welcome to Scala version 2.9.2 (OpenJDK Client VM, Java 1.6.0_24).
Type in expressions to have them evaluated.
Type :help for more information.
// is this what you tried to do?
scala> scala Hello.scala
<console>:1: error: ';' expected but '.' found.
scala Hello.scala
// do this instead
scala> :load Hello.scala
Loading Hello.scala...
HelloWorld
scala>
If you are executing it in scala REPL .You should be using as below
:load [scala file path]
output would be as below
defined "objectname"
Then invoke the main method as the next command
objectname.main(Array())
Refer the below url for more detailed info
https://www.scala-lang.org/documentation/getting-started.html