Jupyter运行scala程序

应用背景

  • 学习 scala, 为后续Spark开发打基础
  • 博文通过 Demo 给出如何在 Jupyter 中定义并调用 Scala程序。
  • Jupyter Notebook 进行Python 开发 逐渐被更多的人所接受、熟知,从而应用于大数据预处理、分析,通过Jupyter 运行Scala 程序讲解文章相对较少。

基础知识

  • 新手,有经验直接略过
    • Scala 菜鸟教程
    • Scala 易百教程
  • 查看官方 API 方法
    • 本地Scala 安装目录 => api 文件夹
      • scala-compiler => index.html
      • scala-library => index.html
      • scala-reflect => index.html

代码及运行结果

object createString {
  
  def main(args : Array[String]) {
    
    val buf = new StringBuilder()
    buf += 'k'
    buf ++= "ngines"
    println("buf is : " + buf.toString)
    println("buf length : " + buf.length())
    
    /*
     * 字符串连接
     *  + 或者  concat 函数
     */
    println("concat buf = ".concat(buf.toString()))
    println("--------------------")
    
    var floatVar = 12.365
    var intVar = 2000
    var stringVar = "Hello kngines.!"
    
    /*
     * 字符串格式化函数
     */
    
    var fs = printf("浮点型变量为 " + 
            "%f, 整型变量为 %d, 字符串为 " + 
            " %s", floatVar, intVar, stringVar)
        
    println(fs)
  }
}

## 调用/执行 scala 对象
createString.main(Array())
  • 执行结果
    Jupyter运行scala程序_第1张图片

References

  • How to run a scala value class in a jupyter notebook
  • scala only classes can have declared but undefined members
  • Where to download the latest Scala API documentation?

Links

  • http://www.scala-lang.org/
  • Download Scala IDE for Eclipse
  • The Scala Programming Language. Github

你可能感兴趣的:(开发语言(Dev))