scala unix时间戳_下载,在Linux,Unix,Windows上安装Scala

scala unix时间戳

Today we will learn how to download Scala and then install Scala on Linux, Unix and Windows OS. Scala runs on top of JVM, so you should have JDK 1.6 or higher version installed already to proceed with Scala installation. Since you are here to learn Scala, I am assuming that you know how to install Java on your system.

今天,我们将学习如何下载Scala,然后在Linux,Unix和Windows OS上安装Scala。 Scala在JVM之上运行,因此您应该已经安装了JDK 1.6或更高版本才能进行Scala安装。 由于您是来这里学习Scala的,因此我假设您知道如何在系统上安装Java。

在Linux系统上下载并安装Scala (Download and Install Scala on Linux systems)

Scala installation on Linux, Ubuntu, Mac OS X or any Unix based system is same, so below steps should work for any *nix system.

在Linux,Ubuntu,Mac OS X或任何基于Unix的系统上的Scala安装是相同的,因此以下步骤适用于任何* nix系统。

  1. Verify the JDK installation on your machine. Open the shell/terminal and type java -version and javac -version.
    $ java -version
    java version "1.8.0_20"
    Java(TM) SE Runtime Environment (build 1.8.0_20-b26)
    Java HotSpot(TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
    
    $ javac -version
    javac 1.8.0_20

    验证计算机上的JDK安装。 打开外壳程序/终端,然后输入java -versionjavac -version
  2. Download Scala Binaries from https://www.scala-lang.org/download/. As of writing this post Scala version is 2.11.6, so you should be getting downloaded file as scala-2.11.6.tgz. Unzip the scala-2.11.6.tgz file using the following command as shown below.
    $ tar -xvzf scala-2.11.6.tgz
    
    scala-2.11.6/
    scala-2.11.6/man/
    scala-2.11.6/man/man1/
    scala-2.11.6/man/man1/scala.1
    scala-2.11.6/man/man1/scalap.1
    scala-2.11.6/man/man1/fsc.1
    scala-2.11.6/man/man1/scaladoc.1
    scala-2.11.6/man/man1/scalac.1
    scala-2.11.6/bin/
    scala-2.11.6/bin/scalac
    ...

    After unzipping, change the path to point to the directory using cd command as shown below.

    For instance my directory is Downloads in which Scala binaries are unzipped.

    Now we are in the downloads directory where Scala binaries are present. Just go to the bin directory.

    [pankaj@local Downloads]$ cd scala-2.11.6
    [pankaj@local scala-2.11.6]$cd bin

    Now enter the scala shell as shown below.

    This is the Scala REPL shell in which we can type programs and see the outcome right in the shell.

    https://www.scala-lang.org/download/下载Scala Binaries。 在撰写本文时,Scala的版本是2.11.6,因此您应该下载的文件为scala-2.11.6.tgz。 如下所示,使用以下命令解压缩scala-2.11.6.tgz文件。
    $ tar -xvzf scala-2.11.6.tgz
    
    scala-2.11.6/
    scala-2.11.6/man/
    scala-2.11.6/man/man1/
    scala-2.11.6/man/man1/scala.1
    scala-2.11.6/man/man1/scalap.1
    scala-2.11.6/man/man1/fsc.1
    scala-2.11.6/man/man1/scaladoc.1
    scala-2.11.6/man/man1/scalac.1
    scala-2.11.6/bin/
    scala-2.11.6/bin/scalac
    ...

    解压缩后,使用cd命令更改路径以指向目录,如下所示。

    例如,我的目录是其中解压缩Scala二进制文件的Downloads。

    现在,我们位于存在Scala二进制文件的downloads目录中。 只需转到bin目录。

    [pankaj@local Downloads]$ cd scala-2.11.6
    [pankaj@local scala-2.11.6]$cd bin

    现在,如下所示输入scala shell。

    这是Scala REPL shell ,我们可以在其中键入程序并直接在shell中查看结果。

在Windows上下载并安装Scala (Download and install Scala on Windows)

  1. Verify the JDK installation on your windows machine by typing the following commands in the command prompt.
    Microsoft Windows [Version 6.3.9600]
    (c) 2013 Microsoft Corporation. All rights reserved.
    
    C:\Users\Pankaj>java -version
    java version "1.8.0_31"
    Java(TM) SE Runtime Environment (build 1.8.0_31-b13)
    Java HotSpot(TM) Client VM (build 25.31-b07, mixed mode, sharing)
    
    C:\Users\Pankaj>javac -version
    javac 1.8.0_20
    
    C:\Users\Pankaj>

    通过在命令提示符下键入以下命令,验证Windows计算机上的JDK安装。
  2. Download Scala binaries from https://www.scala-lang.org/download/. The Scala installer file will be downloaded with .msi extension.

    Double Click or Open scala-2.11.6.msi file and select Run. The Setup Wizard appears, click on Next and complete the installation process. Scala installer will set the Path environment variable too, so that you can run it from anywhere.

    https://www.scala-lang.org/download/下载Scala二进制文件。 Scala安装程序文件将以.msi扩展名下载。

    双击或打开scala-2.11.6.msi文件,然后选择运行 。 出现安装向导,单击“下一步”并完成安装过程。 Scala安装程序还将设置Path环境变量,以便您可以在任何地方运行它。

  3. Open the command prompt and navigate to the bin directory of the installed scala by typing cd command as shown below.
    C:\Program Files (x86)>cd scala
    C:\Program Files (x86)\scala>cd bin
    C:\Program Files (x86)\scala\bin>scala.bat
    Welcome to Scala version 2.11.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_3
    1).
    Type in expressions to have them evaluated.
    Type :help for more information.
    
    scala>

    This is the scala shell in which we can type the programs and see the output in the shell itself. We can check Scala version using below command.

    打开命令提示符,并输入cd命令,导航到已安装scala的bin目录,如下所示。
    C:\Program Files (x86)>cd scala
    C:\Program Files (x86)\scala>cd bin
    C:\Program Files (x86)\scala\bin>scala.bat
    Welcome to Scala version 2.11.6 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_3
    1).
    Type in expressions to have them evaluated.
    Type :help for more information.
    
    scala>

    这是scala shell,我们可以在其中键入程序并在shell本身中查看输出。 我们可以使用以下命令检查Scala版本。

Scala Hello World示例 (Scala Hello World Example)

Let us now see how to write and execute a program in the shell. Below is a simple class Student that we can define in the Scala shell.

现在让我们看看如何在Shell中编写和执行程序。 下面是一个简单的Student类,我们可以在Scala shell中定义。

class Student() {
var id:Int = 0
var age:Int = 0
def studentDetails(i:Int,a:Int) {
id = i
age = a
println("Student Id is :"+id);
println("Student Age is :"+age);
}
}

Output: defined class Student

输出:定义的班级学生

Below image shows how it will look in the Scala shell.

下图显示了它在Scala外壳中的外观。

Here we create a Student class and print the student details in the studentDetails method by passing student id and age as parameter. If there are no errors in the code then a message “defined class Student” is displayed.

在这里,我们创建一个Student类,并通过传递学生ID和年龄作为参数,在studentDetails方法中打印学生详细信息。 如果代码中没有错误,则会显示“已定义班级学生”消息。

Create the student object and invoke the studdetails method by passing the student id and age.

创建学生对象并通过传递学生ID和年龄来调用studdetails方法。

object Stud {
def main(args:Array[String]) {
val stu = new Student();
stu.studentDetails(10,8);
}
}

Returns: defined object Stud

返回:定义的对象Stud

Now run the code by typing Stud.main(null) and you will see below output as shown in the image.

现在,通过键入Stud.main(null)运行代码,您将看到下面的输出,如图所示。

That’s all for now for download and install scala on different operating systems, we will look into more Scala features in coming posts.

现在就可以下载并在不同的操作系统上安装scala,我们将在以后的文章中探讨更多Scala功能。

翻译自: https://www.journaldev.com/7456/download-install-scala-linux-unix-windows

scala unix时间戳

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值