Working Gzip and tar.gz file in Kotlin

This article shows how we can compress, update, and decompress multiple files and folders into a tar.gz file using Kotlin. Table of contents: 1. Gzip vs. Java Zip 2. Add Apache Commons Compress Dependency 3. Compressing Files and Folders into a tar.gz 3.1 file name is too long (>100 bytes) 4. Decompressing a tar.gz File …

Read more

Kotlin – Use `object` for Singleton Patterns

In software development, a singleton is a design pattern that ensures a class has only one instance and provides a global access point to it. While implementing singletons in Java requires additional effort, Kotlin makes it simpler using the object keyword. In this article, we will learn how to create a singleton in Kotlin using …

Read more

Kotlin – Use val Instead of var Wherever Possible

When writing Kotlin code, you should prefer using val instead of var whenever possible. This simple practice enhances code safety, improves performance, and makes your code easier to read and maintain. In this article, we’ll explore why val is preferable, how it compares to var, and provide real-world examples, including a comparison with Java. Table …

Read more

Kotlin – Using ?. and ?.let {} to Avoid Null Checks

One of the most common issues in Java programming is dealing with null values, which can lead to the dreaded NullPointerException (NPE). Kotlin, however, provides built-in features to handle null safety in a more elegant way. Two of the most useful tools for this are ?. (safe call operator) and ?.let {} (scope function). In …

Read more