8000 Merge pull request #32 from oldratlee/master · enjoycodingtime/toBeTopJavaer@ba084dc · GitHub
[go: up one dir, main page]

Skip to content

Commit ba084dc

Browse files
authored
Merge pull request hollischuang#32 from oldratlee/master
《JVM还支持哪些语言》文章的格式优化
2 parents cb90735 + eab1f76 commit ba084dc

File tree

1 file changed

+42
-34
lines changed

1 file changed

+42
-34
lines changed

basics/java-basic/jvm-language.md

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
经常使用IDE的开发者可能会发现,当我们在Intelij IDEA中,鼠标右键想要创建Java类的时候,IDE还会提示创建其他类型的文件,这就是IDE默认支持的一些可以运行在JVM上面的语言,没有提示的,可以通过插件来支持。
1010

11-
<img src="https://www.hollischuang.com/wp-content/uploads/2018/11/languages.png" alt="" width="1102" height="372" class="aligncenter size-full wp-image-2968" />
11+
<img src="https://www.hollischuang.com/wp-content/uploads/2018/11/languages.png" />
1212

1313
目前,可以直接在JVM上运行的语言有很多,今天介绍其中比较重要的九种。每种语言通过一段『HelloWorld』代码进行演示,看看不同语言的语法有何不同。
1414

@@ -18,10 +18,11 @@ Kotlin是一种在Java虚拟机上运行的静态类型编程语言,它也可
1818

1919
#### Hello World In Kotlin
2020

21-
fun main(args: Array<String>) {
22-
println("Hello, world!")
23-
}
24-
21+
```kotlin
22+
fun main(args: Array<String>) {
23+
println("Hello, world!")
24+
}
25+
```
2526

2627
### Groovy
2728

@@ -31,10 +32,11 @@ Apache的Groovy是Java平台上设计的面向对象编程语言。它的语法
3132

3233
#### Hello World In Groovy
3334

34-
static void main(String[] args) {
35-
println('Hello, world!');
36-
}
37-
35+
```groovy
36+
static void main(String[] args) {
37+
println('Hello, world!');
38+
}
39+
```
3840

3941
### Scala
4042

@@ -44,30 +46,33 @@ Scala经常被我们描述为多模式的编程语言,因为它混合了来自
4446

4547
#### Hello World In Scala
4648

47-
object HelloWorld {
48-
def main(args: Array[String]) {
49-
System.out.println("Hello, world!");
50-
}
51-
}
52-
49+
```scala
50+
object HelloWorld {
51+
def main(args: Array[String]) {
52+
System.out.println("Hello, world!");
53+
}
54+
}
55+
```
5356

5457
### Jruby
5558

5659
JRuby是用来桥接Java与Ruby的,它是使用比Groovy更加简短的语法来编写代码,能够让每行代码执行更多的任务。就和Ruby一样,JRuby不仅仅只提供了高级的语法格式。它同样提供了纯粹的面向对象的实现,闭包等等,而且JRuby跟Ruby自身相比多了很多基于Java类库 可以调用,虽然Ruby也有很多类库,但是在数量以及广泛性上是无法跟Java标准类库相比的。
5760

5861
#### Hello World In Jruby
5962

60-
"puts 'Hello, world!'"
61-
63+
```ruby
64+
puts 'Hello, world!'
65+
```
6266

6367
### Jython
6468

6569
Jython,是一个用Java语言写的Python解释器。Jython能够用Python语言来高效生成动态编译的Java字节码。
6670

6771
#### Hello World In Jython
6872

69-
print "Hello, world!"
70-
73+
```py
74+
print "Hello, world!"
75+
```
7176

7277
### Fantom
7378

@@ -77,11 +82,11 @@ Fantom是与Groovy以及JRuby差不多的一样面向对 象的编程语言,
7782

7883
#### Hello World In Fantom
7984

80-
class Hello
81-
{
82-
static Void main() { echo("Hello, world!") }
83-
}
84-
85+
```fantom
86+
class Hello {
87+
static Void main() { echo("Hello, world!") }
88+
}
89+
```
8590

8691
### Clojure
8792

@@ -91,9 +96,10 @@ Clojure是Lisp编程语言在Java平台上的现代、函数式及动态方言
9196

9297
#### Hello World In Clojure
9398

94-
(defn -main [& args]
95-
(println "Hello, World!"))
96-
99+
```clojure
100+
(defn -main [& args]
101+
(println "Hello, World!"))
102+
```
97103

98104
### Rhino
99105

@@ -103,22 +109,24 @@ Rhino的特点是为JavaScript加了个壳,然后嵌入到Java中,这样能
103109

104110
#### Hello World In Rhino
105111

106-
print('Hello, world!')
107-
112+
```js
113+
print('Hello, world!')
114+
```
108115

109116
### Ceylon
110117

111118
Ceylon是一种面向对象,强烈静态类型的编程语言,强调不变性,由Red Hat创建。 Ceylon程序在Java虚拟机上运行,​​可以编译为JavaScript。 语言设计侧重于源代码可读性,可预测性,可扩展性,模块性和元编程性。
112119

113120
#### Hello World In Ceylon
114121

115-
shared void run() {
116-
print("Hello, world!");
117-
}
118-
122+
```ceylon
123+
shared void run() {
124+
print("Hello, world!");
125+
}
126+
```
119127

120128
### 总结
121129

122130
好啦,以上就是目前主流的可以在JVM上面运行的9种语言。加上Java正好10种。如果你是一个Java开发,那么有必要掌握以上9中的一种,这样可以在一些有特殊需求的场景中有更多的选择。推荐在Groovy、Scala、Kotlin中选一个。
123131

124-
[1]: https://www.hollischuang.com/archives/2322
132+
[1]: https://www.hollischuang.com/archives/2322

0 commit comments

Comments
 (0)
0