1.scala shell命令

scala> :help
All commands can be abbreviated, e.g., :he instead of :help.
:edit <id>|<line> edit history
:help [command] print this summary or command-specific help
:history [num] show the history (optional num is commands to show)
:h? <string> search the history
:imports [name name ...] show import history, identifying sources of names
:implicits [-v] show the implicits in scope
:javap <path|class> disassemble a file or class name
:line <id>|<line> place line(s) at the end of history
:load <path> interpret lines in a file
:paste [-raw] [path] enter paste mode or paste a file
:power enable power user mode
:quit exit the interpreter
:replay [options] reset the repl and replay all previous commands
:require <path> add a jar to the classpath
:reset [options] reset the repl to its initial state, forgetting all session entries
:save <path> save replayable session to a file
:sh <command line> run a shell command (result is implicitly => List[String])
:settings <options> update compiler options, if possible; see reset
:silent disable/enable automatic printing of results
:type [-v] <expr> display the type of an expression without evaluating it
:kind [-v] <expr> display the kind of expression's type
:warnings show the suppressed warnings from the most recent line which had any

2.scala基本类型

3.常用特殊字符

\n 换行符,其Unicode编码为 (\u000A) 
\b 回退符,其Unicode编码为 (\u0008) 
\t tab制表符 ,其Unicode编码(\u0009) 
\” 双引号,其Unicode编码为 (\u0022) 
\’ 单引号,其Unicode编码为 (\u0027) 
\ 反斜杆,其Unicode编码为(\u005C)

4.函数

5.类

//采用关键字class定义

class Person {

//类成员必须初始化,否则会报错

//这里定义的是一个公有成员

var name:String=null

}

附录:

import java.sql.{ Connection, DriverManager }
import java.util.{Date, Locale}
import java.text.DateFormat
import java.text.DateFormat._
object Mysql extends App {
// def main(args: Array[String]): Unit = {
// 访问本地MySQL服务器,通过3306端口访问mysql数据库
val url = "jdbc:mysql://localhost:3306/mysql"
//驱动名称
val driver = "com.mysql.jdbc.Driver"
//用户名
val username = "root"
//密码
val password = "1"
//初始化数据连接
var connection: Connection = _
try {
//注册Driver
Class.forName(driver)
//得到连接
connection = DriverManager.getConnection(url, username, password)
val statement = connection.createStatement
//执行查询语句,并返回结果
val rs = statement.executeQuery("SELECT host, user FROM user")
//打印返回结果
while (rs.next) {
val host = rs.getString("host")
val user = rs.getString("user")
println("host = %s, user = %s".format(host, user))
}
} catch {
case e: Exception => e.printStackTrace
}
//关闭连接,释放资源
connection.close
//for循环
var myArray: Array[String] = new Array[String](10);
for (i <- 0 until myArray.length) {
myArray(i) = "value is: " + i;
}
for (value: String <- myArray) {
println(value);
}
for (value: String <- myArray if value.endsWith("5")) {
println(value);
}
val now = new Date
val df = getDateInstance(LONG, Locale.FRANCE)
println(df format now)
//}
val greetStrings =new Array[String](3)
greetStrings(0)="Hello"
greetStrings(1)=","
greetStrings(2)="world!\n"
greetStrings.update(0,"Hello")
greetStrings.update(1,",")
greetStrings.update(2,"world!\n")
for(i <- 0 to 2)
print(greetStrings(i))
val oneTwo = List(1,2)
val threeFour = List(3,4)
val oneTwoThreeFour=oneTwo ::: threeFour
println (oneTwo + " and " + threeFour + " were not mutated.")
println ("Thus, " + oneTwoThreeFour + " is a new list")
//几种循环
def printArgs ( args: Array[String]) : Unit ={
var i=0
while (i < args.length) {
println (args(i))
i+=1
}
}
def printArgs1 ( args: Array[String]) : Unit ={
for( arg <- args)
println(arg)
}
def printArgs2 ( args: Array[String]) : Unit ={
args.foreach(println)
}
//类与对象
class ChecksumAccumulator{
private var sum=0
def add(b:Byte) :Unit = sum +=b
def checksum() : Int = ~ (sum & 0xFF) +1
}
def gcdLoop (x: Long, y:Long) : Long ={
var a=x
var b=y
while( a!=0) {
var temp=a
a=b % a
b = temp
}
b
}
}

  

Spark记录-Scala shell命令的更多相关文章

  1. Spark记录-Scala异常处理与文件I/O

    Scala的异常处理类似许多其他语言(如Java).它不是以正常方式返回值,方法可以通过抛出异常来终止. 但是,Scala实际上并没有检查异常. 当您想要处理异常时,要像Java一样使用try {.. ...

  2. Linux记录用户shell命令

    在/etc/profile中添加下面内容: export LC_ALL=C TMOUT=3600 HISTFILESIZE=2000 HISTSIZE=2000 HISTTIMEFORMAT=&quo ...

  3. Spark记录-Scala集合

    Scala列表 Scala列表与数组非常相似,列表的所有元素都具有相同的类型,但有两个重要的区别. 首先,列表是不可变的,列表的元素不能通过赋值来更改. 其次,列表表示一个链表,而数组是平的. 具有类 ...

  4. Spark记录-Scala多线程

    Scala多线程 多线程是同时执行多个线程的过程. 它允许您独立执行多个操作.可以通过使用多线程来实现多任务.线程是轻量级的子进程,占用较少的内存.多线程用于在Scala中开发并发应用程序. Scal ...

  5. Spark记录-Scala异常与处理

    Scala try-catch语句 Scala提供try和catch块来处理异常.try块用于包含可疑代码.catch块用于处理try块中发生的异常.可以根据需要在程序中有任意数量的try...cat ...

  6. Spark记录-Scala类和对象

    本章将介绍如何在Scala编程中使用类和对象.类是对象的蓝图(或叫模板).定义一个类后,可以使用关键字new来创建一个类的对象. 通过对象可以使用定义的类的所有功能. 下面的图通过一个包含成员变量(n ...

  7. Spark记录-Scala模式匹配

    Scala模式匹配 模式匹配是Scala函数值和闭包后第二大应用功能.Scala为模式匹配提供了极大的支持,处理消息. 模式匹配包括一系列备选项,每个替代项以关键字大小写为单位.每个替代方案包括一个模 ...

  8. Spark记录-Scala数组

    Scala提供了一种数据结构叫作数组,数组是一种存储了相同类型元素的固定大小顺序集合.数组用于存储数据集合,但将数组视为相同类型变量的集合通常更为有用. 可以声明一个数组变量,例如:numbers,使 ...

  9. Spark记录-Scala字符串

    Scala字符串 在Scala中的字符串和Java中的一样,字符串是一个不可变的对象,也就是一个不能修改的对象.可以修改的对象,如数组,称为可变对象.字符串是非常有用的对象,在本节的最后部分,我们将介 ...

随机推荐

  1. 利用JS实现一个简单的二级联动菜单

    前几天在看js的相关内容,所以就简单写了一个二级联动菜单.分享一下. <!DOCTYPE html> <html lang="en"> <head&g ...

  2. 软件工程第二次作业(JUnit的使用)

    初次使用JUnit 感谢学习资源Junit使用的超简单介绍源 一.开发环境及界面截图: 系统   Windows 10      编辑器       eclipse         语言        ...

  3. dokuwiki 配置 sendmail 邮件发送

    dokuwiki 发送邮件有2种方式: 一是直接使用 PHP 自带发送功能,需要配置 PHP.ini 文件, 我没试过,可参考官网 https://www.dokuwiki.org/tips:mail ...

  4. 机器学习英雄访谈录之 DL 实践家:Dominic Monn

    目录 机器学习英雄访谈录之 DL 实践家:Dominic Monn 正文 对我的启发 机器学习英雄访谈录之 DL 实践家:Dominic Monn Sanyam Bhutani 是 Medium 上一 ...

  5. strongSwan配置、运行及测试

    版本信息:strongSwan v5.7.2 1.      编译 tar xvf strongswan-5.7.2.tar.gz ./configure --prefix=/usr/ --sysco ...

  6. 基于skip-gram做推荐系统的想法

    一.人工智能之自然语言处理 自然语言处理(Natural Language Processing, NLP),是人工智能的分支科学,意图是使计算机具备处理人类语言的能力. “处理人类语言的能力”要达到 ...

  7. Linux第一章第二章学习笔记

    第一章 Linux内核简介 1.1 Unix的历史 它是现存操作系统中最强大最优秀的系统. 设计简洁,在发布时提供原代码. 所有东西都被当做文件对待. Unix的内核和其他相关软件是用C语言编写而成的 ...

  8. 回忆--RYU流量监控

    RYU流量监控 前言 Ryu book上的一个流量监控的应用,相对比较好看懂 实验代码 github源码 from ryu.app import simple_switch_13 from ryu.c ...

  9. wia驱动扫描仪

    .net wia驱动扫描仪 通过各种途径,将当前比较流行的驱动扫描仪封装成了一个简单实用的class,调用扫描仪时,只需要重新创建个对象即可,代码如下: using System;using Syst ...

  10. JS开发之CommonJs和AMD/CMD规范

    CommonJS是主要为了JS在后端的表现制定的,他是不适合前端的,AMD(异步模块定义)出现了,它就主要为前端JS的表现制定规范. 在兼容CommonJS的系统中,你可以使用JavaScript开发 ...