
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Difference between Java and Kotlin in Android with Examples
Kotlin was introduced in Android development considering multiple enhancements in Kotlin w.r.t Java. For example:
Less no. of Lines and easier development with the same functionality.
Java: TextView displayText = (TextView) findViewById(R.id.textView); displayText.setText("Hello World"); Kotlin: textView.setText("Hello World")
Compile-time handling of infamous null pointer exception.
var value: String = "abc" // compilation error value = null
Data class instead of POJO.
data class User(val name: String, val age: Int)
The following are some of the important differences between Java and Kotlin.
Sr. No. | Key | Java | Kotlin |
---|---|---|---|
1 | Exceptions | Java uses checked exceptions for exception handling. | Kotlin has no checked exception. It throws compile-time errors. |
2 | Null Handling | Java has not enforced null check thus null pointer exception arises when code is not handling null. | Kotlin enforces the null check at compile time. |
3 | Non-Private Fields | Java constructs have non-private fields. | Kotlin does not allow non-private fields in its constructs. |
4 | Arrays | Java arrays are covariant. | Kotlin arrays are invariant. |
5 | Ternary Operator | Java has a ternary operator. | Kotlin does not support a ternary operator. |
- Related Articles
- Difference Between ‘+’ and ‘append’ in Python with examples
- Difference between "fold" and "reduce" in Kotlin
- Difference between "*" and "Any" in Kotlin generics
- Difference between isNullOrEmpty and isNullOrBlank in Kotlin
- Difference between List and Array types in Kotlin
- Equality checks in Kotlin (Difference between "==" and "===" Operators)
- How to communicate between Activity and Service in Android using Kotlin?
- Difference between a "class" and an "object" in Kotlin
- What's the difference between "!!" and "?" in Kotlin?
- Difference between Android and HTC
- Difference between Linux and Android
- Difference between Parcelable and Serializable in android
- Difference between getDefaultSharedPreferences and getSharedPreferences in Android
- What is the difference between "const" and "val" in Kotlin?
- What is the difference between "var" and "val" in Kotlin?

Advertisements