You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You only need two tools to compile, run, test, and package a Scala project: Java 8 or 11,
140
-
and Scala CLI.
141
-
To install them manually:
142
-
143
-
1. if you don't have Java 8 or 11 installed, download
144
-
Java from [Oracle Java 8](https://www.oracle.com/java/technologies/javase-jdk8-downloads.html), [Oracle Java 11](https://www.oracle.com/java/technologies/javase-jdk11-downloads.html),
145
-
or [AdoptOpenJDK 8/11](https://adoptopenjdk.net/). Refer to [JDK Compatibility](/overviews/jdk-compatibility/overview.html) for Scala/Java compatibility detail.
We recommend committing the scala executable together with your code so that
72
+
everyone working on the project can compile and run the code without needing to install anything (not even Java).
73
+
74
+
### ...or/and install Scala on your computer
75
+
76
+
Follow the documentation from the Scala CLI on
77
+
[how to install and run `scala`](https://scala-cli.virtuslab.org/install).
147
78
148
79
## Using the Scala CLI
149
80
150
-
In a directory of your choice, which we will call `<project-dir>`, create a file named `hello.scala` with the following code:
81
+
This section assumes you downloaded the Scala CLI launcher in a directory of your choice, which we will call
82
+
`<project-dir>`.
83
+
If you installed the Scala CLI on your computer (globally) instead of in your `<project-dir>`, you should run the
84
+
following commands with `scala` instead of `./scala`.
85
+
86
+
Create a file named `hello.scala` with the following code:
151
87
```scala
152
88
//>usingscala{{site.scala-3-version}}
153
89
@@ -161,10 +97,10 @@ the entry point in program execution. The method's type is `Unit`, which means i
161
97
can be thought of as an analogue to the `void` keyword found in other languages. The `println` method will print the `"Hello, World!"`
162
98
string to standard output.
163
99
164
-
To run the program, execute `scala run hello.scala` command from a terminal, within the `<project-dir>` directory. The file will be compiled and executed, with console output
100
+
To run the program, execute `./scala run hello.scala` command from a terminal, within the `<project-dir>` directory. The file will be compiled and executed, with console output
@@ -241,16 +177,16 @@ This program is identical to the one above. However, other toolkit libraries wil
241
177
242
178
### Using the REPL
243
179
244
-
You can execute code interactively using the REPL provided by the `scala` command. Execute `scala` in the console without any arguments.
180
+
You can execute code interactively using the REPL provided by the `scala` command. Execute `./scala` in the console without any arguments.
245
181
```
246
-
$ scala
182
+
$ ./scala
247
183
Welcome to Scala {{site.scala-3-version}} (20-ea, Java OpenJDK 64-Bit Server VM).
248
184
Type in expressions for evaluation. Or try :help.
249
185
250
186
scala>
251
187
```
252
188
253
-
Write a line of code to be executed and press enter.
189
+
Write a line of code to be executed and press enter:
254
190
```
255
191
scala> println("Hello, World!")
256
192
Hello, World!
@@ -266,7 +202,7 @@ val i: Int = 1
266
202
scala>
267
203
```
268
204
269
-
A new value of type `Int` has been created. If you provide an expression that can be evaluated, its result will be stored in an automatically created value.
205
+
A new value of type `Int` has been created. If you provide an expression that can be evaluated, its result will be stored in an automatically created value:
0 commit comments