20 Kotlin interview questions for junior and senior developers

Posted on November 21st, 2019

Kotlin Interview Questions

Android boasts the largest smartphone OS market share, as it currently sits at 76%, while predictions say that it will grow in the future. 

This means that building an Android app can be a successful and lucrative business idea. 

But, for translating this idea into a reality, you need a well-versed and skilled Kotlin developer or a dev team. Kotlin is a general-purpose programming language and as of May 2019, it’s a preferred choice of Android app developers.

Just like Angular.JS is one of the most powerful and useful front-end frameworks for developing web apps – here’s a list of Angular interview questions in case you need someone to help you create amazing UI, the same can be said for Kotlin when it comes to building Android apps. 

However, business owners and HR professionals who are in charge of the screening, interviewing, and hiring process are rarely development experts. This means they aren’t familiar with the nitty-gritty of development from a technical perspective, which can result in their failure to focus on a particular set of skills and characteristics vital for a good Kotlin developer. 

This guide will help you navigate your interviews and identify your ideal hire, and if you need a break for interview questions there are also a few job interview memes to keep you entertained, we aim to please, after all.

job interview questions funny

Interview Questions and Answers for Junior Kotlin Developers

These couple of questions will help you pick a junior developer who’s the right fit for your project. Given that they would work under the supervision of senior Kotlin developers and execute the tasks given by them, it’s essential to understand that your new hire doesn’t have to be an expert in the field but someone with the potential to learn and grow. 

1: What is Kotlin?

A: Kotlin is a statically-typed language that runs on the Java Virtual Machine. It can seamlessly interoperate with Java and is considered an alternative to the standard Java compiler. 

2. Is Kotlin better than Java? 

A: It’s simpler and much cleaner than Java, as it’s more concise and uses fewer lines of code in order to solve the same problems. Besides being generally more efficient and effective, Kotlin is safer in the sense that it prevents certain common coding errors. As a result, there are fewer app crashes and system failures. Kotlin comes with some features that aren’t available in Java, such as smart casts, operator overloading, data classes, null safety, coroutines, to name just a few. 

3. What are extension functions in Kotlin?

A: It’s a mechanism that allows extending a class without the need to inherit from the class or use Decorator or other design patterns. 

4. What is null safety? 

A: This is a feature that prevents a null reference exception, the equivalent of Java’s NullPointerException in real time. 

kotlin job interview questions meme

5. Is there a ternary operator like in Java? 

A: No, there isn’t, but what a ternary operator does can be achieved through an if-else expression. 

6. What’s the difference between val and var in Kotlin?

A: Both are used for declaring a variable. However, while val is a final variable that is immutable and can be initialized only once, var is a general variable that can be assigned multiple times. 

7. What are the basic data types in Kotlin? 

A: Numbers, characters, Booleans, arrays, and strings. 

8. How many constructors are there in Kotlin? 

A: A constructor’s main role is to initialize the properties of a class. In Kotlin, there can be a primary constructor and one or more secondary constructors. 

9. What are the extension methods that Kotlin provides to the Java.io file list? 

A:

  • bufferedReader():read contents of a file to BufferedReader
  • readBytes() : read contents of a file to ByteArray
  • readText(): read contents of a file to a single String
  • forEachLine() : read a file line by line in Kotlin
  • readLines(): read lines in a file to List

10. What are the structural expressions in Kotlin? 

A: There are three structural expressions:

  • Return: helps to return from the closest function or an anonymous function. 
  • Break:  helps to terminate the closest enclosing loop. 
  • Continue: helps proceed to the next step of the closest enclosing loop. 

Interview Questions and Answers for Senior Kotlin Developers 

If you need to hire a more experienced Kotlin developer, here are some questions that can help you pick the one that will be able to run your project properly and monitor junior developers. 

1. What is the difference between const and val? 

A: Const is a keyword used to define compile-time constants, while val is used to define runtime constants. 

2. Is it possible to migrate code from Java to Kotlin? 

A: Yes, it is. IntelliJ IDEA is a tool that can help you do that. 

3. What are data classes in Kotlin?

A data class is similar to a regular class with certain additional functionalities. For example, in order to store data items in Java, it’s necessary to create a class by setting the variables. In Kotlin, all it takes is adding keyword data to the class, and the compiler will automatically generate a default getter and setter. So, basically, there’s no need to write or generate the extensive boilerplate code. 

4. What modifiers are available in Kotlin?

A: Kotlin offers four visibility modifiers:

  • Private: visible inside this class and all its members only.
  • Protected: the same as private, but visible in subclasses too.
  • Internal: visible inside the same module 
  • Public: by default, all the declarations are visible to everyone. 

5. What is a string in Kotlin? 

A:  It’s a basic data type. Strings are immutable and Kotlin has two types of string literals: 

  • Raw strings, which are delimited by a triple quote and can contain newlines, arbitrary text, and any other character.   
  • Escaped strings, which handle special characters by escaping them. 

6. What is the Init Block?  

A: It’s the initializer block and the code inside of it is executed when the primary constructor is instantiated. 

7. Is new a keyword in Kotlin? 

A: No, it’s not and it doesn’t have to be used to instantiate a class. 

8. Are there primitives in Kotlin? 

In a nutshell, there are no out-of-the-box primitives in Kotlin – they can’t be created at a code level. Given that Kotlin has been designed to cooperate with Java and the JVM seamlessly, certain types like int or float can act like primitives in certain cases. 

9. Is there an equivalent for switch in Kotlin?

A: Yes, there is. The When keyword is used instead. 

10. What are deconstructing declarations? 

A: Kotlin comes with a functionality that allows developers to assign multiple values to variables. This kind of syntax allows for creating multiple variables that can be used independently at once.

These 20 questions can help you sift through a large number of Kotlin dev applicants and find the one who’ll help you build amazing Android apps.

Intellij vs. VS Code: Which is best for Java devs?

Posted on November 4th, 2019

When you spend more time in front of your code than you do with your family, you can officially call your IDE (Integrated Development Environment) “home”. Most developers invest quite a bit of time and energy in customizing their digital work environment with plugins, modules, and eye-friendly color themes. After all, it’s where they “live”. 

If your IDE is your home then that makes other developers living in other IDEs your neighbors. When Java developers venture out to their Java neighborhood they are ready to step up and defend the homeland wherever they are called to do so.

Developers in online communities (Reddit, we’re looking at you) will vigorously defend their IDE or coding solution of choice with blowhorns, torches, and pitchforks. The louder supporters will continuously argue about which IDE is best, wholeheartedly believing there is in fact a best IDE that is superior to all others (hint: context is key).

Until recently, Java devs have been somewhat absent the IDE battleground. Some have argued IntelliJ vs Eclipse, with NetBeans making an occasional appearance, but there seems to be an overall consensus that IntelliJ is the leading IDE for Java. Now, there’s a (relatively) new kid on the block – Visual Studio Code – the free code editor from the Microsoft family. 

Now, not every new IDE that pops up on a Hackernoon blog post deserves to be compared with IntelliJ, which has been around for 20 years.

However, VS Code is more than a new kid on the block. In a short period of time, VS Code has been able to break down the wall between IDEs and text editors. VS Code is one of the first to be able to do both and be both lightweight and function as a feature full platform, which has launched it to become the market leader among Javascript developers.

However, when it comes to Java, it’s another story.

(Source: JetBrain Dev Ecosystem Statistics)

Can the new kid on the block usurp the reigning king? And, if so, why and how would it happen? Let’s see.

The Main Difference Between IntelliJ IDEA and VS Code

Microsoft Visual Studio Code is a universal text-based code editor, with some IDE features and a growing Marketplace of plugins and extensions turning it into a fully-fledged IDE. More than anything, VS Code aims to be a flexible polyglot solution for multiple languages and frameworks including C#, VB.NET, F#, JavaScript, TypeScript, Azure, SQL, C++, Python, and Java. It is distributed for free and is open sourced.

JetBrains IntelliJ IDEA is a full-featured IDE aimed mostly at coders developing in Java and Java-based languages like Scala, Kotlin and Groovy. Available for free as IntelliJ IDEA Community Edition and Android Studio, IntelliJ also offers a paid subscription version, the IntelliJ IDEA Ultimate for an annual cost of $500 (for the first year).

Do you stay updated with the latest advancements and trends in software development?

It’s essential to remain informed about new technologies and practices to excel in this constantly evolving industry. Learn how you can leverage AI to optimize your software engineering in 2023.

When should you use VS Code?

When you need to code in .NET or any other non-Java language

VS Code is the only free tool for .NET development out there and probably the most widely adopted. The extensive support for languages and frameworks offered lets you switch between your languages or choice without having to switch IDEs.

When you’re working on primarily visual applications (like games)

VS Code offers comfortable integration between the GUI builder and code editor. For developers working on GUI components or graphic apps, VS Code might be a better fit.

When should you use IntelliJ?

When you’re looking for an IDE that is uniquely focused on Java

When you need a tool to get a specific job done, the most logical thing to do is use one that was built for it, and has proven effective. IntelliJ IDEA is just that and has a variety of plugins designed for Java specific purposes.

It comes down to the classic battle or titan like clash between “all-in-one” VS “best-of-breed”. For a long time, IntelliJ has been considered by many to be the best Java IDE (sorry, Eclipse users). VS Code is brining a new all-in-one IDE offering to the table.

As is usually the case with these types of decisions, if you’re heavy into Java then we would recommend going with the IDE that is designed with that in mind and has working on providing a great Java dev experience for years.

However, keep your eye on VS Code and RedHat’s Java plugin as things can change in a hurry…

When should you choose something else entirely?

When neither gets the job done

Sometimes you come across a project that demands a specific setup and toolset to compile and debug. If it doesn’t work in IntelliJ or VS Code, time to give old Eclipse another go, or try something new altogether.

When the organization you work for requires you use a different IDE

Enterprises often have guidelines and standards in place to ensure all developers are using the same tools. In others, team leaders may prefer developers use their favorite IDE simple because it’s comfortable for them. Can’t really argue with the boss, can you?

Will VS Code overtake IntelliJ’s dominance of the Java block?

Though many are quick to praise the rise of VS Code popularity among developers, when it comes to to the Java developer crowd, most are still loyal residents of IntelliJ IDEA.

Now, some of IntelliJ’s dominance is due to IDE loyalty, and Java developers are a loyal bunch. In our experience, the main driver for IDE selection among developers is previous experience and access to mentorship and guidance from colleagues or teachers. 

However, IntelliJ’s dominance is not without merit and it would appear that the guys at JetBrains are aware of VS Code’s growing market share, especially in Javascript, and not happy merely sitting on their laurels .

That being said, VS Code’s ability to become the IDE of choice for Java developers is, in our humble opinion, not a question of features or plugins but a methodological one. Will the future of writing software consist of a single, robust, software agnostic IDE or will software development be better served by using best-of-breed IDEs? Actually, what do think? Leave your comments in the comment section below.