scala vs java 相同点和差异
本贴是我摘抄自国外网站,用作备忘,也作为分享!
Similarities between Scala and Java
1) Both are JVM based language, Scala produce same byte code as Java and runs on Java Virtual Machine. Similar to Java compiler javac, Scala has a compiler scalac, which compiles Scala code into byte code. At this level, all JVM language like Groovy, JRuby, Scala becomes equals to Java, because they use same memory space, type system and run inside same JVM.
2) You can call Scala from Java and Java from Scala, it offers seems
less integration. Moreover, you can reuse existing application code and
open source Java libraries in Scala.
3) Major Java programming IDE like Eclipse, Netbeans and InetelliJ supports Scala.
4) One more similarity between Scala and Java is that both are Object Oriented, Scala goes one steps further and also supports functional programming paradigm, which is one of it's core strength.
Differences between Scala and Java
2) Scala is designed to express common programming patterns in elegant,
concise and type-safe way. Language itself encourage you to write code
in immutable style, which makes applying concurrency and parallelism
easily.
3) One difference, which some might not notice is learning curve. Scala
has steep learning curve as compared to Java, my opinion may be slightly
biased because I am from Java background, but with so much happening
with little code, Scala can be really tricky to predict. Syntax of Scala
looks confusing and repulsive as compared to Java, but I am sure that
is just the starting hurdle. One way to overcome this hurdle is
following a good Scala book like Programming in Scala or Scala in Action, both are excellent books for a Java developer, who wants to learn Scala
4) One of Scala's cool feature is built-in lazy evaluation, which allows
to defer time consuming computation, until absolutely needed and you
can do this by using a keyword called "lazy" as shown in below code :
image is really slow, so only do it if need to show image
getImages() //lazy
keyword is used for lazy computation
without loading images.
If you love to learn by following examples, then I guess Scala CookBook
is a another good buy, contains tons of examples on different features
of Scala.
5) Some one can argue that Java is more readable than Scala, because of
really nested code in Scala. Since you can define functions inside
function, inside another functions, inside of an object inside of a
class. Code can be very nested. Though some time it may improve clarity,
but if written poorly it can be really tricky to understand.
6) One more difference between Scala and Java is that Scala supports Operator overloading. You can overload nay operator in Java and you can also create new operators for any type, but as you already know, Java doesn't support Operator Overloading.
7) Another major difference between Java and Scala is that functions are objects in Java. Scala treats any method
or function as they are variables. When means, you can pass them around
like Object. You might have seen code, where one Scala function is
accepting another function. In fact this gives the language enormous
power.
8) Let's compared some code written in Scala and Java to see How much different it look:
iList = Arrays.asList(2,
7, 9,
8, 10);
iDoubled = new ArrayList<Integer>();
iList){
% 2 == 0){
9, 8,
10);
% 2 == 0).map(_ * 2)
【注】: 上面的代码,原贴中在标记红色部分是有错误的,估计是typo吧,不管如何,出于技术探索,还是要调试过的代码,不要错代码,至少不要明显有错的代码!
You can see that Scala version is lot succinct and concise than Java
version. You will see more of such samples, once you start learning functional programming
concepts and patterns.
That's all on this article about similarities and differences between Scala and Java. Though they are two separate programming language,
they have lot in common, which is not a bad thing at all and in my
opinion that's the only thing, which will place Scala as Java
alternative, if at all it happens in future.
scala vs java 相同点和差异的更多相关文章
- Scala For Java的一些参考
变量 String yourPast = "Good Java Programmer"; val yourPast : String = "Good Java ...
- 使用Scala实现Java项目的单词计数:串行及Actor版本
其实我想找一门“具有Python的简洁写法和融合Java平台的优势, 同时又足够有挑战性和灵活性”的编程语言. Scala 就是一个不错的选择. Scala 有很多语言特性, 建议先掌握基础常用的: ...
- scala调用java的方法,返回了一个对象链表List<Student>,在scala中遍历该链表获取指定Student的名字name
假设Student类如下: class Student { private int no; private String name; public int getNo() { return no; } ...
- Spark:用Scala和Java实现WordCount
http://www.cnblogs.com/byrhuangqiang/p/4017725.html 为了在IDEA中编写scala,今天安装配置学习了IDEA集成开发环境.IDEA确实很优秀,学会 ...
- IDEA15使用maven编译scala和java
机器安装maven,在IDEA中配置maven的home 创建项目:new-maven–> scala-archetype-simple project structure–>创建src. ...
- C#与Java的语法差异
C#与Java的语法差异C与Java的语法差异前言程序结构基本语法数据类型字符串变量与常量运算符判断语句循环语句访问权限方法数组结构枚举类继承多态运算符重载接口命名空间预处理器指令正则表达式异常IO泛 ...
- scala 与 java 之间的关系
scala来源于java,但又高于java. scala的设计者Martin Odersky就是一个JAVA控,这位牛人设计了javac和编写了jdk中的通用代码.可以说java语言本身就是Marti ...
- 编写Spark的WordCount程序并提交到集群运行[含scala和java两个版本]
编写Spark的WordCount程序并提交到集群运行[含scala和java两个版本] 1. 开发环境 Jdk 1.7.0_72 Maven 3.2.1 Scala 2.10.6 Spark 1.6 ...
- Scala IDEA for Eclipse里用maven来创建scala和java项目代码环境(图文详解)
这篇博客 是在Scala IDEA for Eclipse里手动创建scala代码编写环境. Scala IDE for Eclipse的下载.安装和WordCount的初步使用(本地模式和集群模式) ...
随机推荐
- magento 多域名多店铺
事前指导 我们使用的就是parked domain ,将你要添加的域名指向你的现有magento 文件根目录. 就像预习中提到的,我们有个magento站域名为one.com ,添加新的域名two.c ...
- 四、CCSprite
在介绍CCSprite之前,先要理解游戏开发中的一个核心概念:精灵.精灵也称为游戏对象,它可以用来表示游戏中的任何物体,比如敌人.子弹.甚至是一个背景图片.一段文字.CCSprite可以说是在coco ...
- Azure 云助手正式发布
Azure云服务在中国市场风生水起,越来越多的用户选择Azure作为平台将业务转向云端.随着移动互联网在中国的蓬勃发展,手机应用的体验深入人们的生活及工作.用户管控云服务也不应该只局限于电脑前,而是可 ...
- 主机控制器接口(HCI)
主机控制器接口(HCI)提供了一种访问蓝牙硬件能力的通用接口. HCI固件通过访问基带命令.链路管理器命令.硬件状态寄存器.控制寄存器以及事件寄存器实现对蓝牙硬件的HCI命令. HCI是通过包的方式来 ...
- Java 正则表达式学习总结和一些小例子
从Java1.4起,Java核心API就引入了java.util.regex程序包,它是一种有价值的基础工具,可以用于很多类型的文本处理, 如匹配,搜索,提取和分析结构化内容. java.util.r ...
- ZOJ 1107 FatMouse and Cheese
原题链接 题目大意:FM在一个街道n*n街道的(0,0)点,在每个网格里放着cheese,他要尽可能多的吃这些cheese.有两个规则:1)他跑的总距离不能超过k步:2)下一个节点的cheese的块数 ...
- canvas-绘制时钟
把最近学到的一些canvas技能全部发上来,刚开始写博客,感觉还不太习惯,不过我相信慢慢就会习惯了.不啰嗦了,把代码送上,看不懂的话可以先去学习下基础教程,把基础学好了也就能看懂了. <!DOC ...
- scala言语基础学习二
使用yield和函数式编程转化数组 算法案例(移除第一个负数之后的所有负数) 改良高校方案
- POJ2125 Destroying The Graph (最小点权覆盖集)(网络流最小割)
Destroying The Graph Time Limit: 2000MS Memo ...
- 【HAOI2006】【BZOJ1051】【p1233】最受欢迎的牛
BZOJ难得的水题(其实是HA太弱了) 原题: 每一头牛的愿望就是变成一头最受欢迎的牛.现在有N头牛,给你M对整数(A,B),表示牛A认为牛B受欢迎. 这 种关系是具有传递性的,如果A认为B受欢迎,B ...