Scala is .
Let's try creating a simple program using basic development tools.
- Prerequisite: Scala development environment setup
Creating the First Program in Scala
Using Scala 3 with sbt:
$ cat build.sbt scalaVersion := "3.1.2"
mkdir hello-world && cd $_ sbt
$ sbt [info] Updated file /home/harry/Projects/codeandtips/code/scala/hello-world/project/build.properties: set sbt.version to 1.6.2 [info] welcome to sbt 1.6.2 (Private Build Java 17.0.2) [info] loading project definition from /home/harry/Projects/codeandtips/code/scala/hello-world/project [info] set current project to hello-world (in build file:/home/harry/Projects/codeandtips/code/scala/hello-world/) [info] sbt server started at local:///home/harry/.sbt/1.0/server/c3760365d47f3349d9fa/sock [info] started sbt server sbt:hello-world> help <command> (; <command>)* Runs the provided semicolon-separated commands. about Displays basic information about sbt and the build. tasks Lists the tasks defined for the current project. settings Lists the settings defined for the current project. reload (Re)loads the current project or changes to plugins project or returns from it. new Creates a new sbt build. projects Lists the names of available projects or temporarily adds/removes extra builds to the session. project Displays the current project or changes to the provided `project`. set [every] <setting> Evaluates a Setting and applies it to the current project. session Manipulates session settings. For details, run 'help session'. inspect [tree|uses|definitions|actual] <key> Prints the value for 'key', the defining scope, delegates, related definitions, and dependencies. <log-level> Sets the logging level to 'log-level'. Valid levels: debug, info, warn, error plugins Lists currently available plugins. --addPluginSbtFile=<file> Adds the given *.sbt file to the plugin build. last Displays output from a previous command or the output from a specific task. last-grep Shows lines from the last output for 'key' that match 'pattern'. lastGrep Shows lines from the last output for 'key' that match 'pattern'. export <tasks>+ Executes tasks and displays the equivalent command lines. show <key> Displays the result of evaluating the setting or task associated with 'key'. print <key> Prints the result of evaluating the setting or task associated with 'key' to standard output. all <task>+ Executes all of the specified tasks concurrently. ~ <command> Executes the specified command whenever source files change. help Displays this help message or prints detailed help on requested commands (run 'help <command>'). completions Displays a list of completions for the given argument string (run 'completions <string>'). early(<command>) Schedules a command to run before other commands on startup. exit Terminates the remote client or the build when called from the console shutdown Terminates the build. More command help available using 'help <command>' for: !, +, ++, +-, <, ^, ^^, alias, append, apply, clearCaches, client, eval, iflast, java+, java++, onFailure, reboot, shell, startServer
// without creating hello-world folder, $ sbt new scala/scala-seed.g8 [info] welcome to sbt 1.6.2 (Private Build Java 17.0.2) [info] set current project to new (in build file:/tmp/sbt_1763be97/new/) A minimal Scala project. name [Scala Seed Project]: hello-world Template applied in /home/harry/Projects/codeandtips/code/scala/./hello-world
$ cd hello-world $ sbt run [info] welcome to sbt 1.6.2 (Private Build Java 17.0.2) [info] loading project definition from /home/harry/Projects/codeandtips/code/scala/hello-world/project [info] loading settings for project root from build.sbt ... [info] set current project to hello-world (in build file:/home/harry/Projects/codeandtips/code/scala/hello-world/) [info] running example.Hello hello [success] Total time: 1 s, completed Mar 28, 2022, 10:06:01 PM