Skip to main content

Kotlin vs Java

Recently, you might have come across a word Kotlin, so in this post, I am going to share about Kotlin and how it is different from JAVA?

What is Kotlin?

Kotlin is statically typed programming language developed by JetBrains that runs on Java Virtual Machine. It can also be compiled to JavaScript source code. Kotlin is expressive, concise and powerful as it combines object-oriented Programming and functional programming features. It is focused on interoperability, safety and tooling support. Lately, it is really popular within the Android community and most of the developers are switching towards Kotlin. The reason being that Kotlin reduces the lines of code and make it more convenient process for the developers.


Let's look at the few important differences between Kotlin and Java


Kotlin vs Java :


  • Function Types: Kotlin has the ability to pass the function as a parameter to other functions without resorting to single abstract methods like callable, runnable etc, unlike Java
  •  Null Safety: Kotlin has no danger of getting NullPointerException unlike Java, the reason being that Kotlin is Null safe as all the types in Kotlin are non-nullable (it could not hold null value) but it can be modified to hold null values by adding ? at the end of the variables. Kotlin executes forced checks while compiling and prevents the usage of null variables 
  • Checked Exceptions: Kotlin doesn't have any checked exceptions, so you don't need to declare or catch any exceptions unlike Java. But the efficiency and inefficiency of checked exceptions is still the matter of personal opinion among the developers.
  • Type Casting: In Java often you need to check the type and cast an object, but in Kotlin you don't need to explicitly cast the types as it has a feature of smart type casting which automatically detects the type if you already checked it with Kotlin's 'is' operator.
         if (object is String)
            print(object.length)   // object is automatically casted to String



  • Array Invariance: Arrays in Java are covariant whereas arrays in Kotlin are invariant. For example in Java above code assigns the Number[] value to Object[] variable because of Java array covariance and it will not show any error during compilation but during execution, it will show error.
          Number[] num = new Number[1];
          Object[] objects = num;
          objects[0] = "abc";


  • Support for Constructors: Unlike Java, a Kotlin class can have primary constructors and one or more secondary constructors. The primary constructor is a part of class header.
          class Employee constructor(firstName: String){...}


         The class can also declare secondary constructor which is prefixed with constructor.
     
         class Employee {
            constructor(parent: Employee) {
                parent.children.add(this)
               } 
               }

          
Also, Check out below blog post in JAVA

Tricky Questions in JAVA

Concurrent Hash Map in JAVA


Comments

Popular posts from this blog

Tricky Questions or Puzzles in C ( Updated for 2026)

Updated for 2026 This article was originally written when C/C++ puzzles were commonly asked in interviews. While such language-specific puzzles are less frequent today, the problem-solving and logical reasoning skills tested here remain highly relevant for modern Software Engineering, Data Engineering, SQL, and system design interviews . Why These Puzzles Still Matter in 2026 Although most Software &   Data Engineering interviews today focus on Programming, SQL, data pipelines, cloud platforms, and system design , interviewers still care deeply about how you think . These puzzles test: Logical reasoning Edge-case handling Understanding of execution flow Ability to reason under pressure The language may change , but the thinking patterns do not . How These Skills Apply to Data Engineering Interviews The same skills tested by C/C++ puzzles appear in modern interviews as: SQL edge cases and NULL handling Data pipeline failure scenarios Incremental vs ...

Program to uncompress a string ie a2b3c4 to aabbbcccc

Below is the program to uncompress a string #include<stdio.h> #include<conio.h> #include<stdlib.h> int main() { char str[100]="a2b3c4d8u7"; for(int i=0;str[i]!='\0';i++) { if(i%2!=0) { for(int j=0;j<atoi(&str[i]);j++) { printf("%c",str[i-1]); } } } getch(); } Want to become a Data Engineer? Check out below blog posts  1.  5 Key Skills Every Data Engineer needs in 2023 2.  How to prepare for Data Engineering Interviews 3.  Top 25 Data Engineer Questions

Programs and Puzzles in technical interviews i faced

I have attended interview of nearly 10 companies in my campus placements and sharing their experiences with you,though i did not got selected in any of the companies but i had great experience facing their interviews and it might help you as well in preparation of interviews.Here are some of the puzzles and programs asked to me in interview in some of the good companies. 1) SAP Labs I attended sap lab online test in my college through campus placements.It had 3 sections,the first one is usual aptitude questions which i would say were little tricky to solve.The second section was Programming test in which you were provided snippet of code and you have to complete the code (See Tricky Code Snippets  ).The code are from different data structures like Binary Tree, AVL Tree etc.Then the third section had questions from Database,OS and Networks.After 2-3 hours we got the result and i was shortlisted for the nest round of interviews scheduled next day.Then the next day we had PPT of t...