Kotlin vs Java

Hello world
Java
public static void main(final String[] args) {
    System.out.println("Hello world!");
}
Kotlin
fun main() {
    println("Hello world!")
}

fun main(args: Array<String>) {
    println("Hello World!")
}
Variables I
Java
var x; // compile-time error
final var xx; // compile-time error
final var y = 1;
Kotlin
val x: Int // compile-time error
val y // compile-time error
val z = 2
Variables II
Java
int w;
int z = 2;
z = 3;
w = 1;
Kotlin
var q // compile-time error
var w: Int // compile-time error
var z = 2
Null I
Java
final String name = null;

String lastName;
lastName = null;
Kotlin
val name: String? = null

var lastName: String?
lastName = null

var firstName: String
firstName = null // Compilation error!!
Null II
Java
final Integer length =
    bob != null
        && bob.department != null
        && bob.department.text != null
    ? bob.department.text.length()
    : null;
Kotlin
val length = bob?.department?.text?.length
Elvis operator
Java
final var result = Optional.ofNullable(nullableVariable)
    .flatMap(v -> Optional.ofNullable(v.someNullableMethodCall()))
    .orElseGet(() -> fallbackIfNullMethodCall())
Kotlin
val result = nullableVariable?.someNullableMethodCall() ?: fallbackIfNullMethodCall()
Strings I
Java
final var name = "John";
final var lastName = "Smith";
final var text = "My name is: " + name + " " + lastName;
final var otherText = "My name is: " + name.substring(2);
Kotlin
val name = "John"
val lastName = "Smith"
val text = "My name is: $name $lastName"
val otherText = "My name is: ${name.substring(2)}"
Strings II
Java
final var text = "First Line\n" +
              "Second Line\n" +
              "Third Line";
Kotlin
val text = """
        |First Line
        |Second Line
        |Third Line
""".trimMargin()
Ternary operator
Java
final var text = x > 5 ? "x > 5" : "x <= 5";
Kotlin
val text = if (x > 5) "x > 5" else "x <= 5"
Arrays
Java
var size = 1;

var numbers = new int[size];
numbers[0] = 1;

var bigNumbers = new long[size];

var strings = new String[size];
Kotlin
val size = 1

val numbers = IntArray(size)
numbers[0] = 1

val bigNumbers = LongArray(size)

val strings = Array(size) { String() }
Use
Java
var file = new File("contents.txt");
try {
    var fileReader = new FileReader(file);
    try (var bufferedReader = new BufferedReader(fileReader)) {
        // the bufferedReader is closed automatically
    }
} catch (IOException ex) {
    // handle the exception
}
Kotlin
File("contents.txt")
    .bufferedReader()
    .use {
        // the bufferedReader is closed automatically
    }