Skip to content

Kotlin Learning Pack - A comprehensive collection of 30+ Kotlin examples covering everything from basic syntax to advanced features like coroutines, DSLs, and scope functions. Perfect for beginners and experienced developers.

License

Notifications You must be signed in to change notification settings

raushan728/Kotlin-language

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Kotlin Learning Pack

A comprehensive collection of Kotlin programming examples covering fundamental to advanced concepts. This repository contains 30+ Kotlin source files that demonstrate various aspects of the Kotlin language, from basic syntax to advanced features like coroutines and DSL.

Table of Contents

Overview

This Kotlin Learning Pack is designed for developers who want to learn or improve their Kotlin skills. Each file focuses on a specific concept with practical examples and clear explanations. The examples progress from basic language constructs to advanced Kotlin features.

Prerequisites

Before running these examples, ensure you have the following installed:

  • Java Development Kit (JDK) 8 or higher
  • Kotlin compiler (kotlinc)
  • IntelliJ IDEA (recommended) or any Kotlin-compatible IDE
  • Command line tools (for running via terminal)

Checking Prerequisites

# Check Java version
java -version

# Check Kotlin compiler
kotlinc -version

Installation

Option 1: Using IntelliJ IDEA (Recommended)

  1. Clone the repository:

    git clone https://github.com/raushan728/Kotlin-language.git
    cd Kotlin-language
  2. Open IntelliJ IDEA

  3. Select "Open" and choose the cloned directory

  4. IntelliJ will automatically detect Kotlin files and configure the project

Option 2: Using Command Line

  1. Clone the repository:

    git clone https://github.com/raushan728/Kotlin-language.git
    cd Kotlin-language
  2. Install Kotlin compiler if not already installed:

Windows

Check if you have package managers installed:

winget --version

Install via winget

# Install OpenJDK (if not already installed)
winget install OpenJDK.OpenJDK.17

# Install Kotlin
winget install JetBrains.Kotlin

Manual installation:

macOS

# Install via Homebrew
brew install kotlin

Linux

# Install via Snap
sudo snap install --classic kotlin

# Or install via package manager
# Ubuntu/Debian:
sudo apt install kotlin

# Fedora:
sudo dnf install kotlin

# Arch Linux:
sudo pacman -S kotlin

Usage

Running Individual Files

Using IntelliJ IDEA

  1. Right-click on any .kt file
  2. Select "Run" or press Ctrl+Shift+F10 (Windows/Linux) or Cmd+Shift+R (macOS)

Using Command Line

# Compile and run a specific file
kotlinc filename.kt -include-runtime -d filename.jar
java -jar filename.jar

# Example:
kotlinc 01_Variables.kt -include-runtime -d variables.jar
java -jar variables.jar

Running Multiple Files

# Compile all Kotlin files
kotlinc *.kt -include-runtime -d kotlin-learning.jar
java -jar kotlin-learning.jar

Topics Covered

The repository is organized to cover Kotlin concepts in a progressive manner:

Basic Concepts

  • 01_Variables.kt - Variable declarations (var, val), type inference, and explicit typing
  • 02_DataTypes.kt - Basic data types (Int, String, Boolean, etc.)
  • 03_Strings.kt - String operations, templates, and formatting
  • 04_Operators.kt - Arithmetic, comparison, and logical operators
  • 05_InputOutput.kt - Console input/output operations

Control Flow

  • 06_IfWhen.kt - Conditional statements (if, when expressions)
  • 07_LoopsRanges.kt - For loops, while loops, ranges, and progressions

Functions

  • 08_FunctionsBasics.kt - Function declarations, parameters, default arguments, named parameters
  • 09_HigherOrderLambdas.kt - Higher-order functions, lambda expressions, function references

Null Safety

  • 10_NullSafety.kt - Null safety operators, safe calls, Elvis operator, non-null assertions

Object-Oriented Programming

  • 11_ClassesObjects.kt - Classes, objects, constructors, properties, methods
  • 12_DataClasses.kt - Data classes, destructuring declarations, copy function
  • 13_EnumsSealed.kt - Enums, sealed classes, when expressions with sealed classes
  • 14_InheritanceInterfaces.kt - Inheritance, interfaces, abstract classes, method overriding
  • 15_VisibilityCompanion.kt - Visibility modifiers, companion objects, object declarations
  • 16_ObjectExpressions.kt - Object expressions, anonymous objects, object declarations

Collections and Arrays

  • 17_Collections.kt - Lists, Sets, Maps, mutable vs immutable collections
  • 18_Arrays.kt - Arrays, array operations, primitive arrays vs boxed arrays
  • 19_Generics.kt - Generic classes, functions, type parameters, variance

Advanced Features

  • 20_Extensions.kt - Extension functions, extension properties, scope of extensions
  • 21_ScopeFunctions.kt - let, run, with, apply, also scope functions
  • 22_Exceptions.kt - Exception handling, try-catch-finally, custom exceptions
  • 23_StdIOFiles.kt - File I/O operations, working with files and directories
  • 24_Sequences.kt - Sequences vs collections, lazy evaluation, sequence operations

Concurrency and Advanced Topics

  • 25_CoroutinesBasics.kt - Coroutines, suspend functions, launch, async, await
  • 26_AnnotationsDsl.kt - Custom annotations, DSL creation, type-safe builders
  • 27_InteropJava.kt - Kotlin-Java interoperability, calling Java from Kotlin
  • 28_TypeAliases.kt - Type aliases, creating readable type names
  • 29_SealedInterfaces.kt - Sealed interfaces, exhaustive when expressions
  • 30_Regex.kt - Regular expressions, pattern matching, string manipulation

Running the Examples

Each file is self-contained and can be run independently. The files include:

  1. Main function - Every file has a main() function for easy execution
  2. Comments - Detailed explanations of concepts
  3. Examples - Practical code demonstrations
  4. Output - Print statements showing expected results

Quick Start

  1. Start with basics: Begin with 01_Variables.kt and progress sequentially
  2. Experiment: Modify the code and observe changes
  3. Practice: Create your own variations of the examples
  4. Reference: Use files as reference for your own Kotlin projects

File Organization

The repository contains 30 Kotlin files organized sequentially from basic to advanced concepts. Each file is numbered and focuses on a specific Kotlin topic, making it easy to follow the learning progression.

Contributing

Contributions are welcome! If you find any issues or want to add more examples:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/new-example)
  3. Commit your changes (git commit -am 'Add new example')
  4. Push to the branch (git push origin feature/new-example)
  5. Create a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Author

Raushan Kumar


Additional Resources

About

Kotlin Learning Pack - A comprehensive collection of 30+ Kotlin examples covering everything from basic syntax to advanced features like coroutines, DSLs, and scope functions. Perfect for beginners and experienced developers.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages