Skip to content

Kotlin vs Java or From Java To Kotlin Part 1

  • by
Kotlin vs Java or From Java To Kotlin

Kotlin vs Java syntax

In this article, you will find Kotlin vs java code syntax. Kotlin is a newly launched language and every wants to know about it. Here we are covering a basic point comparison between Kotlin and java.

For Android code syntax in Kotlin follow this tutorial Kotlin Android basic Fundaments

1. Creating Constants and Variables in

JAVA

String name = "www.eyehunt.in";
final String name = "Java vs Kotlin";

Kotlin

var name = "Tutorial Eyehunt"
val name = "Kotlin vs Java"

2. Assigning null value in String

JAVA

String javaStr = null;

Kotlin

var kotlinStr : String?
kotlinStr = null

3. Print Statements

JAVA

System.out.print("tutorial eyehunt");
System.out.println("Kotlin vs java");

Kotlin

print("Tutorial eyehunt")
println("Kotlin vs java")

Its looks very clean and simple in kiting no extra syntax

4. Concatenation two strings

JAVA

String firstName = "Rohit";
String lastName = "Kanojia";
String message = "Full name : " + firstName + " " + lastName;

Kotlin

val firstName = "Rohit"
val lastName = "Kanojia"
val message = "Hello: $firstName $lastName"

5. Defining methods or Function

JAVA

void doSomethingMethod() {
   // logic here
}

Kotlin

fun doSomethingFunction() {
   // logic here
}

6. Methods with Parameters

JAVA

void doMethod(int numbers) {
   // logic here
}

Kotlin

fun doFunction(numbers: Int) {
   // logic here
}

Leave a Reply

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