Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the differences using spring boot with Kotlin and with Java?

What are the differences using spring boot with Kotlin and with Java?

Kotlin is among the three languages you could choose to start your app with https://start.spring.io. So it's supported by the spring boot team. I used it to develop some microservices and as far as I know everything went fine at the end but I would like to have some feedback from other developers because I try to convince my new team to start our new microservices in Kotlin.

Pros:

  • Null safety
  • Clearer code
  • Val over var

Cons:

  • Mockito not Kotlin friendly (I switched to mockk)
  • Code coverage was not out of the box (we had to develop our own plugin)
  • Risk to have Java moving faster than Kotlin
like image 759
Xavier Bouclet Avatar asked Jun 26 '19 02:06

Xavier Bouclet


People also ask

What is the main difference between Kotlin and Java?

Kotlin offers object-oriented and functional features to developers. In contrast, Java only offers object-oriented programming. Kotlin offers extension creation capabilities, whereas Java doesn't offer any extension function. Kotlin doesn't support implicit conversions; however, Java supports implicit conversions.

What is the difference between Java and Spring boot?

What is the difference between Java and Spring? Java is a programming language, while Spring is an open source application framework. Therefore, they cannot be directly compared. However, Java EE (which is Java's own server programming platform) is often compared against Spring framework.

Can spring boot be used with Kotlin?

Spring Boot Gradle plugin automatically uses the Kotlin version declared via the Kotlin Gradle plugin. You can now take a deeper look at the generated application.

Is it better to use Kotlin or Java?

Kotlin is better for: Apps that need to maintain platform independence and be cross-compiled for multiple platforms as well as Android. Kotlin can perform these functions while Java cannot due to its use of bytecode which can only compile code for one specific platform at once.


1 Answers

Since Kotlin is simply a dependency and plugin for Maven (that's it!). It's such a nice, compact, easy-to-grok language that removes all the syntactic fat (opposed to syntactic sugar) that Java provides.

From 5.0.0 onward Kotlin has first-class support from Spring, which effectively means it has all the same guarantees as Java in terms of code working correctly.

Kotlin itself has a ton of interoperability features to smoothly integrate with any already existing Java library, which means you have the same freedom of choice.

Kotlin's Java interop is amazing, and was by no means an afterthought by Jet Brains. Thus Kotlin works nicely with Spring, which provides a lot of the boilerplate functionality for web applications, especially Spring Boot.

These are some points which You already mentioned but I will still have a say about it. Kotlin has a much more compact syntax and its type system allows for much more robust code through null-safety, sealed classes, and immutable/mutable collection distinction, which together significantly reduce development time on any project.

like image 200
Tahir Hussain Mir Avatar answered Nov 14 '22 22:11

Tahir Hussain Mir