- 1、本文档共15页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
A Scala Tutorial for Java programmers(Java程序员的Scala教程)
A Scala Tutorial
for Java programmers
Version 1.3
January 16, 2014
Michel Schinz, Philipp
Haller
PROGRAMMING METHODS LABORATORY
EPFL
SWITZERLAND
2
1 Introduction
This document gives a quick introduction to the Scala language and compiler. It
is intended for people who already have some programming experience and want
an overview of what they can do with Scala. A basic knowledge of object-oriented
programming, especially in Java, is assumed.
2 A first example
As a first example, we will use the standard Hello world program. It is not very fasci-
nating but makes it easy to demonstrate the use of the Scala tools without knowing
too much about the language. Here is how it looks:
object HelloWorld {
def main(args: Array[String]) {
println(Hello, world!)
}
}
The structure of this program should be familiar to Java programmers: it consists
of one method called main which takes the command line arguments, an array of
strings, as parameter; the body of this method consists of a single call to the pre-
defined method println with the friendly greeting as argument. The main method
does not return a value (it is a procedure method). Therefore, it is not necessary to
declare a return type.
What is less familiar to Java programmers is the object declaration containing the
main method. Such a declaration introduces what is commonly known as a single-
ton object, that is a class with a single instance. The declaration above thus declares
both a class called HelloWorld and an instance of that class, also called HelloWorld.
您可能关注的文档
- A Guide to Performing An Arc Flash Hazard (指南执行电弧闪光危害).pdf
- A GUIDE TO PRODUCTS AND SERVICES - Castrol (指导产品和服务嘉实多).pdf
- A Guide To Quantitative Risk Assessment for (定量风险评估指南).pdf
- A Guide to RFID in Libraries - Book Industry (RFID在图书馆,图书行业指南).pdf
- A Guide to Safe Scaffolding - N.C. Department (指导安全的脚手架,北卡罗来纳州的部门).pdf
- A Guide to Scaffolding Safety - Australian Scaffolds(脚手架安全指南澳大利亚的支架).pdf
- A Guide to SuDS in the Urban Landscape(指导泡沫的城市景观).pdf
- A GUIDE TO TORQUE VALUES - Norbar Torque(指南Norbar扭矩扭矩值).pdf
- A guide to thermoplastic polyurethanes (TPU)(热塑性聚氨酯(TPU)指南).pdf
- A Guide To Volleyball Basics - Tri State Volunteers(排球基础指南三州的志愿者).pdf
文档评论(0)