- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Difference between Java and Kotlin in Android with Examples
85 Lectures 6 hours
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.
|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.|
- Difference between isNullOrEmpty and isNullOrBlank in Kotlin
- Difference between List and Array types in Kotlin
- Difference between Parcelable and Serializable in android
- Difference between Parcel able and Serializable in android
- How to communicate between Activity and Service in Android using Kotlin?
- Difference between Go and Java.
- Difference Between C++ and Java
- Difference between "fold" and "reduce" in Kotlin
- Difference between "*" and "Any" in Kotlin generics
- Java toUpperCase() with examples
- Equality checks in Kotlin (Difference between "==" and "===" Operators)
- Difference between Java and C language
- Difference between ArrayList and CopyOnWriteArrayList in Java
- Difference between HashMap and ConcurrentHashMap in Java