林子雨教材在线参考资料
centos7的java安装
1 2 3 4 5 6 7 8
| yum list installed |grep java
yum -y list java*
yum -y install java-1.8.0-openjdk*
java -version
|
scala安装
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| cd /usr/local
wget https://downloads.lightbend.com/scala/2.11.8/scala-2.11.8.tgz
tar -xzvf scala-2.11.8.tgz
mv scala scala-2.11.8
cd ~ vim .bash_profile
export SCALA_HOME=/usr/local/scala export PATH=$PATH:$SCALA_HOME/bin
source .bash_profile
scala Welcome to Scala 2.11.8 (OpenJDK 64-Bit Server VM, Java 1.8.0_272). Type in expressions for evaluation. Or try :help.
scala>
|
scala简易入门
建立一个文件夹存放scala文件,并创建文件 demo1.scala
1 2
| println("this is first line") println("this is second line")
|
进入scala,执行 :load /usr/local/scalapro/mycode/demo1.scala
1 2 3 4
| scala> :load /usr/local/scalapro/mycode/demo1.scala Loading /usr/local/scalapro/mycode/demo1.scala... this is first line this is second line
|
退出,新建 helloworld.scala
1 2 3 4 5
| object helloworld{ def main(args:Array[String]){ println("hello world") } }
|
执行 scala helloworld.scala
即可输出 helloworld
执行 scalac helloworld.scala
可生成2个文件 helloworld.class helloworld$.class
,前者为可在java虚拟机上运行的字节码文件,然后使用命令 scala -classpath . helloworld
运行该程序
scala基础知识