The Scala programming language is a burgeoning force in Information Technology …
Object-Oriented Meets Functional
Have the best of both worlds. Construct elegant class hierarchies for maximum code reuse and extensibility, implement their behavior using higher-order functions. Or anything in-between.
… and we want to find out more about it, so today we start down that long and winding road. So where else would a beginner begin, barring running a complete sample project, as to construct our own Hello World Scala application, with a lot of help from others (thanks), ourselves.
Steps in getting together a Scala command line Hello World application, and to ready the NetBeans 8.0.2 IDE for Scala Sbt Project creations into the future, given our NetBeans 8.0.2 / No Scala / Java SE 1.7 starting point, involved …
- Java SE 1.8 is needed for Scala (via sbt) work and we installed via HTTP://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
- Install Scala 2.12.0 via https://www.scala-lang.org/download/
- Make it work on command line in our /usr/local/bin/scala-2.12.0 base directory, on our command line (via Terminal) $PATH
- Advice of https://www.macports.org/install.php had us reinstalling Xcode command line tools from Apple Developer Store because of recent upgrade of Mac OS X to macOS Sierra Version 10.12.1 … followed by
sudo xcodebuild -license
- Reinstall base Macports via Download button of https://www.macports.org/install.php because of recent upgrade of Mac OS X to macOS Sierra Version 10.12.1
- Install sbt version 0.13.11 via Macports …
sudo port install sbt
… alternatively install via sbt landing page …The interactive build tool
Use Scala to define your tasks. Then run them in parallel from the shell. - Start up NetBeans 8.0.2
- Tools -> Java Platforms show Java SE 1.8
- Tools -> Scala Platforms shows no relationships
- Tools -> Plugins -> Available Plugins … Sort and check all the Scala ones and -> Install … as you can see a bit of with today’s tutorial picture
- Tools -> Scala -> Sources tab -> Add JAR/Folder… and add all the *.jar in /usr/local/bin/scala-2.12.0/lib directory
- At Terminal command line …
$ cd $HOME
$ pwd
/Library/pgAgent
$ mkdir scala_sbt_hello_world
$ cd scala_sbt_hello_world
$ echo 'object Hi { def main(args: Array[String]) = println("Hello World ... Scala fans!") }' > helloworld.scala
$ sbt
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=384m; support was removed in 8.0
[info] Set current project to scala_sbt_hello_world (in build file:/Library/pgAgent/scala_sbt_hello_world/)
> run
[info] Updating {file:/Library/pgAgent/scala_sbt_hello_world/}scala_sbt_hello_world...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Compiling 1 Scala source to /Library/pgAgent/scala_sbt_hello_world/target/scala-2.10/classes...
[info] 'compiler-interface' not yet compiled for Scala 2.10.6. Compiling...
[info] Compilation completed in 24.13 s
[info] Running Hi
Hello World ... Scala fans!
[success] Total time: 44 s, completed 04/12/2016 3:37:10 PM
> exit
$
Great help (thanks heaps) came from …
- https://blogs.oracle.com/geertjan/entry/10_steps_to_happiness_with … for all but the NetBeans 8.0.2 (Java SE 1.8 Scala 2.12.0) -> New Project (Scala) list only having Scala SBT Project option … so also consulted …
- HTTP://www.scala-sbt.org/0.12.4/docs/Getting-Started/Hello.html
You may face the same dilemmas as us, so below is a list of pertinent “other” parts of the Scala research and development …
- HTTP://stackoverflow.com/questions/8461013/how-to-check-sbt-version
- https://github.com/dcaoyuan/nbsbt
- HTTP://stackoverflow.com/questions/31683539/scala-application-missing-in-netbeans-8-0-2-projects-under-windows
- HTTP://forums.netbeans.org/topic62461.html
- https://sourceforge.net/projects/erlybird/files/nb-scala/
- HTTP://www.scala-lang.org/news/2.12.0
- HTTP://www.java2s.com/Code/Jar/s/Downloadscalacompilersrcjar.htm
- https://docs.oracle.com/javase/8/docs/technotes/guides/install/mac_jdk.html
- HTTP://stackoverflow.com/questions/18144660/what-is-path-of-jdk-on-mac
- HTTP://crunchify.com/where-is-java-installed-on-my-mac-osx-system/
- https://netbeans.org/kb/docs/java/javase-jdk8.html#platform
We hope, if you are one of those interested in Scala, this tutorial helps a little with your launching into finding out more.
If this was interesting you may be interested in this too.
2 Responses to Scala Hello World Primer Tutorial