kotlin vs java code example

Example 1: java vs javascript

/*
JavaScript can be used to do neat things like creating 
animation in HTML. ... JavaScript code is run on a 
browser only, while Java creates applications that run 
in a virtual machine or browser. Java is an OOP 
(object-oriented programming) language, and JavaScript is
specifically an OOP scripting language.
*/

Example 2: what is kotlin

Kotlin is a cross-platform, statically typed, general-purpose programming language with type inference. Kotlin is designed to interoperate fully with Java, and the JVM version of its standard library depends on the Java Class Library, but type inference allows its syntax to be more concise. Kotlin mainly targets the JVM, but also compiles to JavaScript or native code (via LLVM). Language development costs are borne by JetBrains, while the Kotlin Foundation protects the Kotlin trademark.
On 7 May 2019, Google announced that the Kotlin programming language is now its preferred language for Android app developers. Since the release of Android Studio 3.0 in October 2017, Kotlin has been included as an alternative to the standard Java compiler. The Android Kotlin compiler lets the user choose between targeting Java 6 or Java 8 compatible bytecode.

Example 3: kotlin vs java

chunk of code written in Kotlin is much smaller compared to Java, as it is less verbose and less code means fewer bugs. Kotlin compiles the code to a bytecode which can be executed in the JVM. Thus, all the libraries and frameworks made in Java can be moved and run in a Kotlin project.

Example 4: Kotlin is like java

// if is an expression, so ternary operation not needed
val loaded = true
val status = if (loaded) "Ready" else "Loading..."
// "Ready

Example 5: setbackground java

setBackground(Color.cyan);   // sets predefined color cyan to background of frame

Example 6: kotlin vs java

Kotlin is a language built on and entirely backwards-compatible with Java.
While Java is Object-Oriented first, Kotlin supports a blend
of OO and functional paradigms. For further information, refer to
kotlinlang.org