Java vs. Groovy, Scala, Kotlin – Basic Syntax Comparison of JVM Languages

This article provides basic comparison of JVM languages Groovy vs. Scala vs. Kotlin with Java. For advanced feature comparison refer to Features Comparison of JVM Languages with code examples

Hello World code, compile & execute

Java:

With Java 11, javac can be avoided for single file executions. Example

Groovy:

As groovy is mainly script-like language, it is run directly. But it can be compiled and executed as well.

Scala:

Kotlin:

Notice that generated class name ‘HelloWorldKt’ is derived from file name HelloWorld.kt



Instance variable, constructor & method

Java

Groovy

Groovy syntax is same when it comes to class, method, constructor & methods. Main intentions are to use groovy as script & not as plain old OOPS.

Scala

Constructor is included in class definition unlike Java. Method syntax is also different i.e.  <access-modifier> def <func-name> (<arg-name>:<arg-type>,...) : <return-type> = { }

Kotlin

Many similarities with Scala here. Constructor is included in class definition. Method syntax is also somewhat similar to Scala i.e.  <access-modifier> fun <func-name> (<arg-name>:<arg-type>,...) : <return-type> { }



Leave a Reply

Your email address will not be published. Required fields are marked *