Fundamentals 4 min read

Master Kotlin Quickly: Side-by-Side Java vs Kotlin Syntax Guide

This article presents a concise side‑by‑side comparison of Java and Kotlin syntax—including logging, variables, null handling, loops, and method definitions—through practical code snippets, helping Java‑experienced developers transition to Kotlin efficiently.

Programmer DD
Programmer DD
Programmer DD
Master Kotlin Quickly: Side-by-Side Java vs Kotlin Syntax Guide

We’ve compiled a GitHub project “from-java-to-kotlin” that demonstrates side‑by‑side syntax differences between Java and Kotlin, helping Java‑proficient developers transition smoothly.

Logging

// Java
System.out.print("Amit Shekhar");
System.out.println("Amit Shekhar");
// Kotlin
print("Amit Shekhar")
println("Amit Shekhar")

Constants and Variables

// Java
String name = "Amit Shekhar";
final String name = "Amit Shekhar";
// Kotlin
var name = "Amit Shekhar"
val name = "Amit Shekhar"

Null Declaration

// Java
String otherName;
otherName = null;
// Kotlin
var otherName: String?
otherName = null

For Loops

// Java
for (int i = 1; i <= 10; i++) { }
for (int i = 1; i < 10; i++) { }
for (int i = 10; i >= 0; i--) { }
for (int i = 1; i <= 10; i += 2) { }
for (int i = 10; i >= 0; i -= 2) { }
for (String item : collection) { }
for (Map.Entry<String, String> entry : map.entrySet()) { }
// Kotlin
for (i in 1..10) { }
for (i in 1 until 10) { }
for (i in 10 downTo 0) { }
for (i in 1..10 step 2) { }
for (i in 10 downTo 0 step 2) { }
for (item in collection) { }
for ((key, value) in map) { }

Method Definitions

// Java
void doSomething() {
    // logic here
}
void doSomething(int... numbers) {
    // logic here
}
// Kotlin
fun doSomething() {
    // logic here
}
fun doSomething(vararg numbers: Int) {
    // logic here
}

The project focuses on practical code examples rather than theory, making the differences clear and easy to grasp.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

JavaKotlinTutorialSyntax Comparison
Programmer DD
Written by

Programmer DD

A tinkering programmer and author of "Spring Cloud Microservices in Action"

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.