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.
- Overview
- Prerequisites
- Installation
- Usage
- Topics Covered
- Running the Examples
- Contributing
- License
- Author
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.
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)
# Check Java version
java -version
# Check Kotlin compiler
kotlinc -version-
Clone the repository:
git clone https://github.com/raushan728/Kotlin-language.git cd Kotlin-language -
Open IntelliJ IDEA
-
Select "Open" and choose the cloned directory
-
IntelliJ will automatically detect Kotlin files and configure the project
-
Clone the repository:
git clone https://github.com/raushan728/Kotlin-language.git cd Kotlin-language -
Install Kotlin compiler if not already installed:
Check if you have package managers installed:
winget --versionInstall via winget
# Install OpenJDK (if not already installed)
winget install OpenJDK.OpenJDK.17
# Install Kotlin
winget install JetBrains.KotlinManual installation:
- Download from Kotlin official site
- Download OpenJDK from Oracle or Adoptium
# Install via Homebrew
brew install kotlin# 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- Right-click on any
.ktfile - Select "Run" or press
Ctrl+Shift+F10(Windows/Linux) orCmd+Shift+R(macOS)
# 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# Compile all Kotlin files
kotlinc *.kt -include-runtime -d kotlin-learning.jar
java -jar kotlin-learning.jarThe repository is organized to cover Kotlin concepts in a progressive manner:
- 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
- 06_IfWhen.kt - Conditional statements (if, when expressions)
- 07_LoopsRanges.kt - For loops, while loops, ranges, and progressions
- 08_FunctionsBasics.kt - Function declarations, parameters, default arguments, named parameters
- 09_HigherOrderLambdas.kt - Higher-order functions, lambda expressions, function references
- 10_NullSafety.kt - Null safety operators, safe calls, Elvis operator, non-null assertions
- 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
- 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
- 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
- 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
Each file is self-contained and can be run independently. The files include:
- Main function - Every file has a
main()function for easy execution - Comments - Detailed explanations of concepts
- Examples - Practical code demonstrations
- Output - Print statements showing expected results
- Start with basics: Begin with
01_Variables.ktand progress sequentially - Experiment: Modify the code and observe changes
- Practice: Create your own variations of the examples
- Reference: Use files as reference for your own Kotlin projects
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.
Contributions are welcome! If you find any issues or want to add more examples:
- Fork the repository
- Create a feature branch (
git checkout -b feature/new-example) - Commit your changes (
git commit -am 'Add new example') - Push to the branch (
git push origin feature/new-example) - Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Raushan Kumar