2017-07-01
java环境
需要java sdk 1.7 以上
[zhouhh@mainServer hadoop-3.0.0-alpha3]$ !cat
cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)
[zhouhh@mainServer hadoop-3.0.0-alpha3]$ echo $JAVA_HOME
/etc/alternatives/java_sdk_openjdk
[zhouhh@mainServer
[zhouhh@mainServer hadoop-3.0.0-alpha3]$ java -version
openjdk version "1.8.0_131"
OpenJDK Runtime Environment (build 1.8.0_131-b12)
OpenJDK 64-Bit Server VM (build 25.131-b12, mixed mode)
hadoop-3.0.0-alpha3]$ javac -version
javac 1.8.0_131
下载安装scala
下载安装scala只需找到对应版本,解压即可. 下载地址:http://www.scala-lang.org/download/
[zhouhh@msvr ~]$ wget https://downloads.lightbend.com/scala/2.12.2/scala-2.12.2.tgz
解压
[zhouhh@msvr scala-2.12.2]$ ./bin/scala
Welcome to Scala 2.12.2 (OpenJDK 64-Bit Server VM, Java 1.8.0_131).
Type in expressions for evaluation. Or try :help.
[zhouhh@msvr ~]$ vi .bashrc
# scala
export SCALA_HOME="${HOME}/java/scala"
export PATH="$SCALA_HOME/bin:$PATH"
[zhouhh@msvr ~]$ source .bashrc
[zhouhh@msvr ~]$ scala
Welcome to Scala 2.12.2 (OpenJDK 64-Bit Server VM, Java 1.8.0_131).
Type in expressions for evaluation. Or try :help.
scala> 1+1
res1: Int = 2
编写测试程序
[zhouhh@msvr scala]$ cat hello.scala
object HelloWorld {
def main(args: Array[String]): Unit = {
println("Hello, 中国!")
}
}
[zhouhh@msvr scala]$ scala hello.scala
Hello, 中国!
在命令行执行
scala> object HelloWorld {
| def main(args: Array[String]):Unit = {
|
| print("Hello, 中国")
| }
| }
defined object HelloWorld
scala> HelloWorld.main(Array())
Hello, 中国
编译
[zhouhh@msvr scala]$ scalac hello.scala
[zhouhh@msvr scala]$ scala HelloWorld
Hello, 中国!
继承app
可以不用写入口的main
scala> object HelloWorld extends App {
| print("hello,中国2")
| }
defined object HelloWorld
scala> HelloWorld.main(Array())
hello,中国2
脚本化
[zhouhh@msvr scala]$ cat hello.sh
#!/usr/bin/env scala
object HelloWorld extends App {
println("Hello, 中国!")
}
HelloWorld.main(args)
[zhouhh@msvr scala]$ ./hello.sh
/home/zhouhh/test/scala/./hello.sh:5: warning: Script has a main object but statement is disallowed
HelloWorld.main(args)
^
one warning found
Hello, 中国!
如非注明转载, 均为原创. 本站遵循知识共享CC协议,转载请注明来源
FEATURED TAGS
css
vc6
http
automake
linux
make
makefile
voip
乱码
awk
flash
vista
vi
vim
javascript
pietty
putty
ssh
posix
subversion
svn
windows
删除
编译
多线程
wxwidgets
ie
ubuntu
开源
c
python
bash
备份
性能
scp
汉字
log
ruby
中文
bug
msn
nginx
php
shell
wordpress
mqueue
android
eclipse
java
mac
ios
html5
js
mysql
protobuf
apache
hadoop
install
iocp
twisted
centos
mapreduce
hbase
thrift
tutorial
hive
erlang
lucene
hdfs
sqoop
utf8
filter
草原
yarn
ganglia
恢复
scrapy
django
fsimage
flume
tail
flume-ng
mining
scala
go
kafka
gradle
cassandra
baas
spring
postgres
maven
mybatis
mongodb
https
nodejs
镜像
心理学
机器学习
Keras
theano
anaconda
docker
spark
akka-http
json
群论
区块链
加密
抽象代数
离散对数
同余
欧拉函数
扩展欧几里德算法
ES6
node-inspect
debug
win10
vscode
挖矿